问题描述
MUST
和 SHOULD
在 ES 中的 bool 查询有什么区别?
What is the difference between MUST
and SHOULD
bool query in ES?
如果我仅想要包含我的术语的结果,我应该使用 must
吗?
If I ONLY want results that contain my terms should I then use must
?
我有一个查询应该只包含某些值,并且没有日期/时间戳比今天的时间/日期更低的结果 - 现在
I have a query that should only contain certain values, and also no results that has a lower date/timestamp than todays time/date - NOW
还有
我可以像下面的代码一样在一个 must 中使用多个过滤器吗:
Can i use multiple filters inside a must like the code bellow:
"filtered": {
"filter": {
"bool" : {
"must" : {
"term" : { "type" : 1 }
"term" : { "totals" : 14 }
"term" : { "groupId" : 3 }
"range" : {
"expires" : {
"gte": "now"
}
}
},
推荐答案
must 表示:子句(查询)必须出现在匹配的文档中.这些子句必须匹配,例如逻辑AND.
must means: The clause (query) must appear in matching documents. These clauses must match, like logical AND.
应该的意思是:这些子句中至少有一个必须匹配,比如逻辑OR.
should means: At least one of these clauses must match, like logical OR.
基本上它们像逻辑运算符 AND 和 OR 一样使用.请参阅这个.
Basically they are used like logical operators AND and OR. See this.
现在在 布尔查询:
must 表示:must 匹配要包含的文档的子句.
must means: Clauses that must match for the document to be included.
should 表示:如果这些子句匹配,则增加_score
;否则,它们不起作用.它们只是用来细化每个文档的相关性分数.
should means: If these clauses match, they increase the _score
; otherwise, they have no effect. They are simply used to refine the relevance score for each document.
是的,您可以在 must
中使用多个过滤器.
Yes you can use multiple filters inside must
.
这篇关于Elasticsearch MUST 和 SHOULD bool 查询的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!