Elasticsearch必须和应该布尔查询之间的区别 [英] Elasticsearch difference between MUST and SHOULD bool query
问题描述
ES中的必须
和应该 c bool查询之间有什么区别?
What is the difference between MUST
and SHOULD
bool query in ES?
如果我仅想要包含我的条款的结果,那么我应该使用必须
吗?
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
也
我可以在下面的代码中使用多个过滤器吗?
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"
}
}
},
推荐答案
必须表示:子句(查询)必须出现在整理文件。这些子句必须匹配,例如逻辑 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 means: Clauses that must match for the document to be included.
应该的意思是:如果这些子句匹配,则它们会增加 _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.
是的,您可以在<$ c $中使用多个过滤器c>必须。
这篇关于Elasticsearch必须和应该布尔查询之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!