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