ElasticSearch:检查嵌套对象数组是否为空 [英] ElasticSearch: check if nested object array is empty

查看:602
本文介绍了ElasticSearch:检查嵌套对象数组是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取字段中没有任何对象的所有文档?

How do I go about fetching all documents w/o any objects in a field?

我具有以下映射:

"properties" : {
  "name": {
    "type": "text"
  },
  "nestedArray": {
    "type": "nested",
    "properties": {
      "prop1": {
        "type": "text"
      },
      "prop2": {
        "type": "text"
      }
    }
  }
}

,我想获取 nestedArray为空或不存在的所有文档。

and I want to get all documents where "nestedArray" is empty or doesn't exist.

我正在使用elasticSearch 5.0

I'm using elasticSearch 5.0

推荐答案

我认为存在查询将解决此问题。尝试以下查询

I think exists query would solve this problem. Try following query

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "nestedArray",
            "query": {
              "bool": {
                "filter": {
                  "exists": {
                    "field": "nestedArray"
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}

这篇关于ElasticSearch:检查嵌套对象数组是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆