繁体   English   中英

Elasticsearch-使用匹配查询和术语查询的“ OR”查询条件

[英]Elasticsearch - “OR” query condition using match query and term query

我有以下匹配查询字符串:

curl -XGET 'my-es.com/my_indice/_search?pretty' -d '{
  "size" : 10,
  "query" : {
    "bool" : {
      "must" : [ {
        "match" : {
          "state" : {
            "query" : ["ACTIVE", "INACTIVE"],
            "type" : "boolean"
          }
        }
      }]
    }
  }
}'

我猜它的意思是"state" = "ACTIVE" or "state" = "INACTIVE" ,但实际上它执行的是"state" = "INACTIVE"

然后我尝试了术语查询字符串:

curl -XGET 'my-es.com/my_indice/_search?pretty' -d '{
  "size" : 10,
  "query" : {
    "bool" : {
      "must" : [{
         "terms" : { "state" : ["ACTIVE", "INACTIVE"] }
      }]
    }
  }
}'

它执行"state" = "ACTIVE" or "state" = "INACTIVE" ,显示术语查询通过数组支持多个OR条件。

我很好奇为什么匹配查询不支持通过数组的OR条件? 并且它不显示任何语法错误。

match查询仅支持指定一个字符串值。 官方match文档中没有明确指定它,但是如果您愿意阅读MatchQueryParser.java一些源代码, MatchQueryParser.java可以看到在解析query字段时,解析器将跳过标记以分隔开头和结尾。数组,并始终使用最新的解析value覆盖该value ,因此为什么您要查看看到的内容,即该state仅与INACTIVE匹配。

但是,您可以做的是将两个标记放在同一个字符串中,如下所示,这两个标记都将被考虑在内:

curl -XGET 'my-es.com/my_indice/_search?pretty' -d '{
  "size" : 10,
  "query" : {
    "bool" : {
      "must" : [ {
        "match" : {
          "state" : {
            "query" : "ACTIVE INACTIVE",
            "type" : "boolean"
          }
        }
      }]
    }
  }
}'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM