gpt4 book ai didi

elasticsearch - elasticsearch中查询DSL中的must和filter有什么区别?

转载 作者:行者123 更新时间:2023-11-29 02:42:58 25 4
gpt4 key购买 nike

我是 Elasticsearch 的新手,我对 must 和 filter 感到困惑。我想在我的条款之间执行一个与操作,所以我这样做了

POST/xyz/_search

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

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

POST/xyz/_search

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

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

最佳答案

must 对分数有贡献。在 filter 中,查询的分数被忽略。

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

你可以查看这个link

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

要了解分数是如何计算的,请参阅此 link

关于elasticsearch - elasticsearch中查询DSL中的must和filter有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43349044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com