【问题标题】:Elastic search combine match and should弹性搜索结合匹配和应该
【发布时间】:2021-08-25 00:22:14
【问题描述】:

我想创建一个可以使用 match 的查询,并且该 match 应该只考虑另一个字段值为 null 或某个特定值的行。

比如:

where field1 like 'string' and field2 is null or field2 = 123

在JS客户端可以吗?

【问题讨论】:

    标签: elasticsearch search elasticsearch-dsl


    【解决方案1】:

    您可以将bool/must/shouldexistswildcard query 结合使用

    {
      "query": {
        "bool": {
          "must": [
            {
              "wildcard": {
                "field1": "string*"
              }
            },
            {
              "bool": {
                "should": [
                  {
                    "term": {
                      "field2": 123
                    }
                  },
                  {
                    "bool": {
                      "must_not": {
                        "exists": {
                          "field": "field2"
                        }
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

    • 是的,这就是我需要的!问题是我想使用匹配而不是通配符,并且也使用模糊性。因此,我创建了一个匹配而不是通配符,它​​可以工作! match 的坏处是,如果一个字符串有多个 SAME 单词,它会优先考虑这些单词。
    猜你喜欢
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    相关资源
    最近更新 更多