elasticsearch中Query DSL中的must和filter有什么区别? [英] What is the difference between must and filter in Query DSL in elasticsearch?

查看:41
本文介绍了elasticsearch中Query DSL中的must和filter有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是弹性搜索的新手,我对 must 和 filter 感到困惑.我想在我的条款之间执行一个 and 操作,所以我这样做了

I am new to elastic search and I am confused between must and filter. I want to perform an and operation between my terms, so I did this

POST/xyz/_search

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "city": "city1"
                    }
                },
                {
                    "term": {
                        "saleType": "sale_type1"
                    }
                }
            ]
        }
    }
}

这给了我匹配这两个术语的所需结果,并使用这样的过滤器

which gave me the required results matching both the terms, and on using filter like this

POST/xyz/_search

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "city": "city1"
                    }
                }
            ],
            "filter": {
                "term": {
                    "saleType": "sale_type1"
                }
            }
        }
    }
}

我得到了相同的结果,那么我什么时候应该使用 must 以及什么时候应该使用过滤器?有什么区别?

I get the same result, so when should I use must and when should I use filter? What is the difference?

推荐答案

must 有助于得分.在filter中,查询的分数被忽略.

must contributes to the score. In filter, the score of the query is ignored.

mustfilter 中,子句(查询)必须出现在匹配的文档中.这就是得到相同结果的原因.

In both must and filter, the clause(query) must appear in matching documents. This is the reason for getting same results.

您可以查看此链接

得分

每个文档的相关性分数由一个称为 _score 的正浮点数表示._score 越高,文档越相关.

The relevance score of each document is represented by a positive floating-point number called the _score. The higher the _score, the more relevant the document.

查询子句为每个文档生成一个_score.

A query clause generates a _score for each document.

要了解分数的计算方式,请参阅此链接

To know how score is calculated, refer this link

这篇关于elasticsearch中Query DSL中的must和filter有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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