Query DSL- Exists Query

走远了吗. 提交于 2020-02-05 02:48:44

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 null or []

  • The field has "index" : false set in the mapping

  • The length of the field value exceeded an ignore_above setting in the mapping

  • The field value was malformed and ignore_malformed was 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 null or [], these values will indicate the field does exist:

    如果JSON值为null[],则认为该字段不存在,下面这些值被认为字段存在:

    • Empty strings, such as "" or "-"

    • Arrays containing null and 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!