elasticsearch--- Exists Query

Posted tingtingbai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch--- Exists Query相关的知识,希望对你有一定的参考价值。

Exists Queryedit

Returns documents that have at least one non-null value in the original field:

GET /_search
{
    "query": {
        "exists" : { "field" : "user" }
    }
}
 

For instance, these documents would all match the above query:

{ "user": "jane" }
{ "user": "" } 
技术分享图片
{ "user": "-" } 
技术分享图片
{ "user": ["jane"] }
{ "user": ["jane", null ] } 
技术分享图片

技术分享图片

An empty string is a non-null value.

技术分享图片

Even though the standard analyzer would emit zero tokens, the original field is non-null.

技术分享图片

At least one non-null value is required.

These documents would not match the above query:

{ "user": null }
{ "user": [] } 
技术分享图片
{ "user": [null] } 
技术分享图片
{ "foo":  "bar" } 
技术分享图片

技术分享图片

This field has no values.

技术分享图片

At least one non-null value is required.

技术分享图片

The user field is missing completely.

null_value mappingedit

If the field mapping includes the null_value setting then explicit null values are replaced with the specified null_value. For instance, if the user field were mapped as follows:

PUT /example
{
  "mappings": {
    "doc": {
      "properties": {
        "user": {
          "type": "keyword",
          "null_value": "_null_"
        }
      }
    }
  }
}
 

then explicit null values would be indexed as the string _null_, and the following docs would match the exists filter:

{ "user": null }
{ "user": [null] }

However, these docs—without explicit null values—would still have no values in the user field and thus would not match the exists filter:

{ "user": [] }
{ "foo": "bar" }

missing queryedit

There isn’t a missing query. Instead use the exists query inside a must_not clause as follows:

GET /_search
{
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "user"
                }
            }
        }
    }
}

以上是关于elasticsearch--- Exists Query的主要内容,如果未能解决你的问题,请参考以下文章

ElasticSearch系列 - SpringBoot整合ES:查询字段不为空的文档 exists

ElasticSearch创建索引报错:ElasticsearchStatusException[type=resource_already_exists_exception, reason=inde

elasticsearch常用命令之_refresh_delete_by_querymappings创建索引结构exists_sourcebool查询(mustshould)大于小于符号

ElasticSearch 如何查询缺失(missing)字段数据

ElasticSearch添加mapping

Elasticsearch 字段为空(null)记录查询