存在与否检索 exists query

返回包含字段索引值的文档。

由于多种原因,文档字段的索引值可能不存在:

  • 源JSON中的字段是null[]
  • 该字段已"index" : false在映射中设置
  • 字段值的长度超出ignore_above了映射中设置
  • 字段值格式错误,并且ignore_malformed已在映射中定义
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "exists": {
      "field": "user"
    }
  }
}
'

要查找缺少字段索引值的文档,请 查询中使用must_not exists查询。

以下搜索返回缺少该user.id字段的索引值的文档

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "user.id"
        }
      }
    }
  }
}
'
原文地址:https://www.cnblogs.com/Mint-diary/p/14498234.html