0

如果我有三个包含字段 [result1, result2, result3] ElasticSearch 可以返回非空或非空字段吗?

我的意思是不在查询过滤器中,Elasticsearch 中是否有源或包含过滤器?

4

1 回答 1

0

是的。比如说,要获取 result2 为 null 且 result1 不为 null 的所有文档您可以使用以下查询:

{
  "query": {
        "bool": {
          "must": [
            {
              "exists": {
                  "field": "result1"
              }
            },
            {
              "bool": {
                  "must_not": {
                      "exists": {
                          "field": "result2"
                      }
                  }
              }
            }
          ]
        }
    }
}

要获取 result2 为 nullresult1 不为 null 的文档,请将存在条件查询包装在should周围,然后包装在 bool 周围。

于 2019-11-04T22:39:44.213 回答