[英]Functions score returns same score for all documents
我正在使用函數分數和采樣器聚合來匹配上次訪問的文檔。
ES查詢
{
"query": {
"function_score": {
"boost_mode": "replace", // we need to replace document score with the result of the functions,
"query": {
},
"functions": [
{
"field_value_factor": { // return `lastvisited` value as score
"field": "visited_time"
}
,"weight":1
}
]
}
},
"size": 10000
}
響應
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 1.45973969E12,
"hits" : [ {
"_index" : "idx0",
"_type" : "8001",
"_id" : "null-100-1459739724631",
"_score" : 1.45973969E12,
"_routing" : "100",
"_source" : {
"visited_time" : 1459739724636
}
}, {
"_index" : "idx0",
"_type" : "8001",
"_id" : "null-101-1459708570522",
"_score" : 1.45970862E12,
"_routing" : "101",
"_source" : {
"visited_time" : 1459708570525
}
}, {
"_index" : "idx0",
"_type" : "8001",
"_id" : "null-101-1459708599619",
"_score" : 1.45970862E12,
"_routing" : "101",
"_source" : {
"visited_time" : 1459708599620
}
}, {
"_index" : "idx0",
"_type" : "8001",
"_id" : "null-100-1459708476386",
"_score" : 1.45970849E12,
"_routing" : "100",
"_source" : {
"visited_time" : 1459708476387
}
}, {
"_index" : "idx0",
"_type" : "8001",
"_id" : "null-100-1459708421417",
"_score" : 1.45970836E12,
"_routing" : "100",
"_source" : {
"visited_time" : 1459708421492
}
} ]
}
}
我不知道為什么它返回相同的文檔分數?
您的查詢很好,但我想您要處理的數字的精度很高。 文檔的分數是double
精度值,而不是long
。 因此,在將long
值轉換為double
,會損失一些精度,因此您會發現某些結果是混亂的。 請注意,只有第二個和第三個結果是亂序的。 我想除非您要處理低精度值,否則沒有簡單的方法可以解決此問題。
但是對於您要解決的特定問題,有一個簡單的解決方案。 您可以使用排序來解決上述問題。 使用以下查詢:
{
"query": {
// query goes here
},
"sort": [
{
"visited_time": {
"order": "desc"
}
}
],
"size": 10000
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.