ElasticSearch在filter中组合OR和AND子句

ut6juiuv  于 7个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(85)

我有一个ElasticSearch 7.7查询,带有几个过滤器(我不想计入分数的条件),看起来像这样:

{
  "from": 0,
  "size": 100,
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
        {
          "term": {
            "type": 4
          }
        },
        {
          "term": {
            "gender": "female"
          }
        }
      ]
    }
  }
}

字符串
我想在两个性别过滤器中添加一个OR子句,以便过滤所有带有type=4 AND(gender=female OR gender=unisex)的文档。这可能吗?

bogh5gae

bogh5gae1#

可以使用should子句

{
  "from": 0,
  "size": 100,
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
        {
          "term": {
            "type": 4
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "gender": "female"
                }
              },
              {
                "term": {
                  "gender": "unisex"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

字符串

相关问题