问题描述
我是弹性搜索的新手,我对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以及什么时候应该使用filter?有什么区别?
I get the same result, so when should I use must and when should I use filter? What is the difference?
推荐答案
必须
有助于得分。在过滤器
中,查询的分数将被忽略。
must
contributes to the score. In filter
, the score of the query is ignored.
在两个必须
和 filter
,子句(查询)必须出现在匹配的文档中。这就是获得相同结果的原因。
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.
查询子句生成<$每个文档c $ c> _score 。
要知道如何计算分数,请参考此
To know how score is calculated, refer this link
这篇关于elasticsearch的Query DSL中must和filter有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!