在 Elasticsearch 中,使用 exists 查询的方式如下:
GET /my_index/posts/_search{"query" : {"constant_score" : {"filter" : {"exists" : { "field" : "tags" }}}}}
缺失查询
SELECT tags
FROM posts
WHERE tags IS NULL
GET /my_index/posts/_search{"query" : {"constant_score" : {"filter": {"missing" : { "field" : "tags" }}}}}
对象的存在与缺失
不仅可以过滤核心类型, exists and missing 查询 还可以处理一个对象的内部字段。
{"bool": {"should": [{ "exists": { "field": "name.first" }},{ "exists": { "field": "name.last" }}]}}
