这种查询返回包含字段索引值的文档。简单的来说,就是查询文档中是否包含field
指定的字段;
这个查询只有一个参数,field:要搜索的字段的名词
- 如果为
null
或[]
,会触发异常,parsing_exception: [exists] unknown token [VALUE_NULL] after [field]
; - 如果为
""
,会触发异常,illegal_argument_exception
查找缺少字段索引值的文档,可以使用bool查询中的must_not。
请求示例
GET blak_new/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "address"
}
}
}
}
}
返回结果
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "blak_new",
"_type" : "_doc",
"_id" : "1009",
"_score" : 0.0,
"_source" : {
"account_number" : 164,
"balance" : 9101,
"firstname" : "Cummings",
"lastname" : "Holt",
"age" : 26,
"gender" : "F",
"employer" : "Comtrak",
"email" : "[email protected]",
"city" : "Chaparrito",
"state" : "WI"
}
}
]
}
}