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

rod*_*757 5 elasticsearch

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

我有以下映射:

"properties" : {
  "name": {
    "type": "text"
  },
  "nestedArray": {
    "type": "nested",
    "properties": {
      "prop1": {
        "type": "text"
      },
      "prop2": {
        "type": "text"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望得到"nestedArray"为空或不存在的所有文档.

我正在使用elasticSearch 5.0

Chi*_*h25 8

我认为存在查询会解决这个问题.尝试以下查询

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "nestedArray",
            "query": {
              "bool": {
                "filter": {
                  "exists": {
                    "field": "nestedArray"
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,我正在尝试存在查询,但我切换了嵌套和布尔值。 (2认同)