1
以下是我的function_score查询。我想给产品质量更好的文档提供额外的分数。ElasticSearch函数分数查询
但是,搜索响应中的_score始终为0.我错过了什么?谢谢。
当我删除bool查询并用一个术语过滤器替换它时,得分不为零。我猜这是关于查询布尔,但无法弄清楚为什么。
Elasticsearch版本是2.4
{
"from": 0,
"size": 20,
"query": {
"function_score": {
"query": {
"bool": {
"filter": [
{
"bool": {
"should": {
"terms": {
"categories.category1Id": [
63
]
}
}
}
}
]
}
},
"functions": [
{
"gauss": {
"updatedDate": {
"origin": "2016-10-03 05:10:18",
"scale": "0.5h",
"decay": 0.1,
"offset": "1h"
}
}
},
{
"filter": {
"term": {
"productQuality": "EXCELLENT"
}
},
"weight": 7
},
{
"filter": {
"term": {
"productQuality": "HIGH"
}
},
"weight": 5
},
{
"filter": {
"term": {
"productQuality": "MEDIUM"
}
},
"weight": 3
},
{
"filter": {
"term": {
"productQuality": "LOW"
}
},
"weight": 1
}
],
"score_mode": "sum"
}
}
}
您的查询的第一个部分是一个过滤器。过滤器只会返回一个常数分数。您可以使用explain api来查看查询的工作原理:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html – jay
@jay是对的,['bool/filter'查询不提供评分](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#_scoring_with_literal_bool_filter_literal) – Val