Elasticsearch必须和应该布尔查询之间的区别 [英] Elasticsearch difference between MUST and SHOULD bool query

查看:133
本文介绍了Elasticsearch必须和应该布尔查询之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆