【问题标题】:Using NOT and OR together in Elastic search在弹性搜索中同时使用 NOT 和 OR
【发布时间】:2017-11-29 16:11:54
【问题描述】:

这是我在弹性搜索中用于过滤满足一个条件或不满足其他条件的记录的查询。

{
    "query": 
    {
        "query_string": 
        {
            "query": "(NOT col1: \"val1\") OR (col2: val2)",
            "analyze_wildcard": true
}}}

问题是我无法在 nodejs 中编写等效语法来提取信息。我们不能在这里使用 must_not 因为它是一个 OR 条件

【问题讨论】:

    标签: node.js elasticsearch


    【解决方案1】:

    您将在 should 数组中设置这两个条件,因为如果有人匹配您将在结果中获得记录,您将必须使用 must matchmust_not match

    {
      "query": {
        "bool": {
          "should": [
            {
              "bool": {
                "must_not": {
                  "match": {
                    "col1": {
                      "query": "val1",
                      "type": "phrase"
                    }
                  }
                }
              }
            },
            {
              "match": {
                "col2": {
                  "query": "val2",
                  "type": "phrase"
                }
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-31
      • 2016-12-31
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 2018-07-01
      相关资源
      最近更新 更多