【问题标题】:Elasticsearch DSL bool query for filtration用于过滤的 Elasticsearch DSL bool 查询
【发布时间】:2021-05-10 08:30:06
【问题描述】:

我有一个如下的 Elasticsearch DSL 查询

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "api": "A"
          }
        },
        {
          "match_phrase": {
            "api": "B"
          }
        },
        {
          "match_phrase": {
            "api": "C"
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

据我了解,这有点像

匹配 if (api = A or api = B or api = C)

我想在第三次检查中添加另一个检查不同字段的条件。

例如 match if (api = A or api = B or (api = C and another_field = D) ) 知道怎么做吗?

【问题讨论】:

    标签: elasticsearch kibana


    【解决方案1】:

    你可以使用bool/must查询的组合

    {
      "query": {
        "bool": {
          "should": [
            {
              "match_phrase": {
                "api": "A"
              }
            },
            {
              "match_phrase": {
                "api": "B"
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "match_phrase": {
                      "api": "C"
                    }
                  },
                  {
                    "match_phrase": {
                      "another_field": "D"
                    }
                  }
                ]
              }
            }
          ],
          "minimum_should_match": 1
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 2021-03-02
      相关资源
      最近更新 更多