elasticsearch 如何在Elastic查询中对多个字段执行负或

wztqucjr  于 2023-04-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(97)

假设我有一个这个Map的Elastic文档:

{
  "title": "XYZ",
  "description": "ABC",
  "type": "A"
}

我想要一个查询,返回所有的文件,要么有titledescription失踪或两个领域都失踪。与类型是'A'
我已经尝试过了,但我不知道如何添加description条件。

{
  "query": {
    "bool": {
      "must_not": [{
                     "exists": {
                       "field": "title"
                     }
                   }],
      "must": {
        "term": {
          "type": "A"
        }
      }
    }
  }
}
vhmi4jdf

vhmi4jdf1#

你可以这样做:

{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "type": "A"
        }
      },
      "minimum_should_match": 1,
      "should": [
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "title"
              }
            }
          }
        },
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "description"
              }
            }
          }
        }
      ]
    }
  }
}

相关问题