2017-02-16 171 views
0

我想下面Elasticsearch衰減函數得分

PUT test/foo/1 
{ 
    "num": 100 
} 

GET test/foo/_search 
{ 
    "query" : { 
    "function_score" : { 
     "query" : { 
     "match" : { 
      "num": 100 
     } 
     }, 
     "functions" : [ 
     { 
      "filter" : { 
      "match_all" : { 
      } 
      }, 
      "gauss" : { 
      "num" : { 
       "origin": 0, 
       "scale" : 500, 
       "offset" : 0, 
       "decay" : 0.1 
      }, 
      "multi_value_mode" : "MIN" 
      } 
     } 
     ], 
     "score_mode" : "sum", 
     "max_boost" : 3.4028235E38 
    } 
    } 
} 

--- 

{ 
    "hits": { 
    "total": 1, 
    "max_score": 0.91201085, 
    "hits": [ 
     { 
     "_index": "test", 
     "_type": "foo", 
     "_id": "1", 
     "_score": 0.91201085, 
     "_source": { 
      "num": 100 
     } 
     } 
    ] 
    } 
} 

在我使用的總和作爲評分模式。由於查詢的得分是1,衰變函數的得分是0.91201085我期望得分是1.91201085。我錯過了什麼?

回答

1

使用「boot_mode」:「sum」。您還可以使用explain查詢瞭解文檔是如何拿下

POST testindexy/_search 
{ 
    "query" : { 
    "function_score" : { 
     "query" : { 
     "match" : { 
      "num": 100 
     } 
     }, 
     "functions" : [ 
     { 
      "filter" : { 
      "match_all" : { 
      } 
      }, 
      "gauss" : { 
      "num" : { 
       "origin": 0, 
       "scale" : 500, 
       "offset" : 0, 
       "decay" : 0.1 
      }, 
      "multi_value_mode" : "MIN" 
      } 
     } 
     ], 
     "boost_mode": "sum", 
     "score_mode" : "sum", 
     "max_boost" : 3.4028235E38 
    } 
    } 
} 
+1

沒錯,'boost_mode'是結合了function_score成績查詢分數,而'score_mode'是針對不同的分數相結合的內部'functions'。 – christinabo