我的映射是:
"properties": { "user": { "type": "nested", "properties": { "id": { "type": "integer" }, "is_active": { "type": "boolean", "null_value": false }, "username": { "type": "string" } } },
我想获取所有没有user字段的文档。
user
我试过了:
GET /index/type/_search { "query": { "bool": { "must_not": [ { "exists": { "field": "user" } } ] } } }
返回所有文档。基于ElasticSearch2.x,存在用于嵌套字段的过滤器不起作用的问题,我也尝试过:
GET /index/type/_search { "query": { "nested": { "path": "user", "query": { "bool": { "must_not": [ { "exists": { "field": "user" } } ] } } } } }
返回0个文档。
使所有缺少该user字段的文档的正确查询是什么?
我找到了正确的语法,应该是:
GET /index/type/_search { "query": { "bool": { "must_not": [ { "nested": { "path": "user", "query": { "exists": { "field": "user" } } } } ] } } }