Elasticsearch-"OR"使用匹配查询和词条查询的查询条件 [英] Elasticsearch - "OR" query condition using match query and term query
问题描述
我有以下 match 查询字符串:
curl -XGET'my-es.com/my_indice/_search?pretty'-d'{大小":10,询问" : {布尔":{必须" : [ {比赛" : {状态" : {"query":["ACTIVE","INACTIVE"],"type":布尔值"}}}]}}}'
我猜这意味着"state" ="ACTIVE"或"state" ="INACTIVE"
,但实际上它执行的是"state" ="INACTIVE"
./p>
然后我尝试了 term 查询字符串:
curl -XGET'my-es.com/my_indice/_search?pretty'-d'{大小":10,询问" : {布尔":{必须" : [{"terms":{"state":["ACTIVE","INACTIVE"]}}]}}}'
它执行"state" ="ACTIVE"或"state" ="INACTIVE"
,显示 term 查询通过以下方式支持多个OR条件数组.
我很好奇为什么 match 查询不通过数组支持 OR 条件?而且它不显示任何语法错误.
I have following match query string: I guess it means Then I tried term query string: It performs I'm curious about why match query does not support OR condition via an array? And it does not show any syntax error. The What you can do, however, is to put both tokens inside the same string like below, and both tokens will be taken into account:
这篇关于Elasticsearch-"OR"使用匹配查询和词条查询的查询条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! match
查询仅支持指定一个字符串值.在官方 match
文档,但是如果您愿意阅读 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"
, but actually it performs "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"
, showing term query supports multiple OR conditions via an array.match
query only supports a single string value to be specified. It is not explicitly specified in the official match
documentation, but if you're willing to read some source code for MatchQueryParser.java
, you can see that while parsing the query
field, the parser will skip the tokens delimiting the start and end of the array and always override the value
with the latest one being parsed, hence why you're seeing what you see, i.e. that state
will be matched with INACTIVE
only.curl -XGET 'my-es.com/my_indice/_search?pretty' -d '{
"size" : 10,
"query" : {
"bool" : {
"must" : [ {
"match" : {
"state" : {
"query" : "ACTIVE INACTIVE",
"type" : "boolean"
}
}
}]
}
}
}'