ElasticSearch:检查嵌套对象数组是否为空

0yg35tkg  于 2022-11-02  发布在  ElasticSearch
关注(0)|答案(2)|浏览(127)

如何获取字段中没有任何对象的所有文档?
我有以下Map:

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

并且我想获取所有“nestedArray”为空或不存在的文档。
我使用的是ElasticSearch5.0

c9qzyr3d

c9qzyr3d1#

我认为exists query可以解决此问题。请尝试以下查询

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

flseospp2#

"试试这个"

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

相关问题