這種查詢返回包含字段索引值的文檔。簡單的來說,就是查詢文檔中是否包含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"
}
}
]
}
}