elasticsearch:多个字段,如果存在则返回true

oprakyz7  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(2)|浏览(932)

es版本: 5.2 alpine 我有这样一份文件:

{
    "field1": null,
    "field2": "xyz"
    "field3": null
}

如果上面的任何字段存在/不为空,我想返回文档。

"filter": {
     "bool": {
          "must": [
           {
               "exists": {
                    "field": ["field1","field2"]
                }
           }]
     }
}

但我有以下错误。 [exists] unknown token [START_ARRAY] after [field] 你知道如何使用这个es版本吗?
谢谢。

syqv5f0l

syqv5f0l1#

如果字段值存在,我不确定您是否要返回文档,或者同时返回值。用于退回满足条件的文件。
这会有帮助,
你可以用 should 查询方式 minimum should match 作为1。

"filter": {
   "bool": {
      "should": [
         { "exists": { "field": "field1 } },
         { "exists": { "field": "field2 } },
       ],
      "minimum_should_match" : 1,
   }
}

试试吧,我希望你的版本也能用。

a9wyjsp7

a9wyjsp72#

不能在中传递多个字段 exists 查询。对每个字段使用exists查询并将它们 Package 在 should 条款如下:

{
  "query": {
    "bool": {
      "should": [
        {
          "exists": {
            "field": "field1"
          }
        },
        {
          "exists": {
            "field": "field2"
          }
        },
        {
          "exists": {
            "field": "field3"
          }
        }
      ]
    }
  }
}

相关问题