2016-06-13 27 views
0

我爲我的文檔創建了一個自定義評分函數,該函數僅爲每個文檔返回字段a的值。但由於某種原因,在下面的示例中,結果中_score的最後幾位與每個文檔的值a的最後幾位不同。這裏發生了什麼?Elasticsearch中的自定義評分函數不會返回預期字段值

PUT test/doc/1 
{ 
    "a": 851459198 
} 

PUT test/doc/2 
{ 
    "a": 984968088 
} 

GET test/_search 
{ 
    "query": { 
    "function_score": { 
     "script_score": { 
     "script": { 
      "inline": "doc[\"a\"].value" 
     } 
     } 
    } 
    } 
} 

這將返回以下內容:

{ 
    "took": 16, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 2, 
    "max_score": 984968060, 
    "hits": [ 
     { 
     "_index": "test", 
     "_type": "doc", 
     "_id": "2", 
     "_score": 984968060, 
     "_source": { 
      "a": 984968088 
     } 
     }, 
     { 
     "_index": "test", 
     "_type": "doc", 
     "_id": "1", 
     "_score": 851459200, 
     "_source": { 
      "a": 851459198 
     } 
     } 
    ] 
    } 
} 

爲什麼_score比外地a的值不同?

我使用Elasticsearch 2.1.1

回答

0

_score值在內部硬編碼爲float如果你想利用它只能準確地表示整數達價值134217728.因此,在得分函數中,存儲爲大於該數字的字段時,它將溢出緩衝區並被截斷。見this github issue