Exists Query
存在查询
Returns documents that contain an indexed value for a field.
返回字段中包含索引值的文档。
An indexed value may not exist for a document’s field due to a variety of reasons:
由于多种原因,索引值可能不存在于文档的字段中:
-
The field in the source JSON is
nullor[] -
The field has
"index" : falseset in the mapping -
The length of the field value exceeded an
ignore_abovesetting in the mapping -
The field value was malformed and
ignore_malformedwas defined in the mapping -
源JSON中的字段是
null或[] -
字段在mapping中设置为
"index" : false -
字段值的长度超出了mapping中设置的
ignore_above -
字段值格式错误,并且mapping中设置的了
ignore_malformed
Example requestedit
GET /_search
{
"query": {
"exists": {
"field": "user"
}
}
}
Copy as cURLView in Console
Top-level parameters for exists
exists的一级参数
-
field(Required, string) Name of the field you wish to search.
(必需,字符串)您要搜索的字段的名称。
While a field is deemed non-existent if the JSON value is
nullor[], these values will indicate the field does exist:如果JSON值为
null或[],则认为该字段不存在,下面这些值被认为字段存在:-
Empty strings, such as
""or"-" -
Arrays containing
nulland another value, such as[null, "foo"] -
A custom
null-value, defined in field mapping -
空字符串,例如
""或"-" -
包含
null和另一个值的数组,例如[null, "foo"] -
在mapping中设置的自定义
null-value
-
Notes
Find documents missing indexed values
查找缺少索引值的文档
To find documents that are missing an indexed value for a field, use the must_not boolean query with the exists query.
要查找字段缺少索引值的文档,请在must_not 布尔查询 中使用exists查询。
The following search returns documents that are missing an indexed value for the user field.
以下搜索返回字段中缺少user索引值的文档。
GET /_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "user"
}
}
}
}
}
Copy as cURLView in Console
来源:CSDN
作者:oowgsoo
链接:https://blog.csdn.net/oowgsoo/article/details/104174670