elasticsearch 打分精度
elasticsearch 原文What Is Relevance?edit
We’ve mentioned that, by default, results are returned in descending order of relevance. But what is relevance? How is it calculated?
The relevance score of each document is represented by a positive floating-point number called the _score. The higher the _score, the more relevant the document.
所以,elasticsearch中分数是 浮点类型的 。
IEEE 754
这里就不细说什么是IEEE 754了,就直接讲具体内容,有兴趣的可以自己百度。
float
符号位(S):1bit指数位(E):8bit尾数位(M):23bit
float的尾数:23位,其范围为:0~223,而223=8388608,所以float的精度为6~7位,能保证6位为绝对精确,7位一般也是正确的,8位就不一定了(但不是说8位就绝对不对了)
那为什么elasticsearch 要用float呢,看了一下源代码 FiltersFunctionFactorScorer 类
https://s4.运维网.com/wyfs02/M00/97/E8/wKiom1k09Vyw7-SGAADl2K3Aueo722.png-wh_500x0-wm_3-wmp_4-s_114025662.png
看到computeScore 还是double 类型的,但是 return scoreCombiner.combine 却变成了float,
https://s5.运维网.com/wyfs02/M00/97/E8/wKiom1k09hfBsxovAAAzaMQxB4Y683.png-wh_500x0-wm_3-wmp_4-s_1443483207.png
继续看
https://s4.运维网.com/wyfs02/M01/97/E9/wKioL1k09nnw_28zAAAitFj-TJk779.png-wh_500x0-wm_3-wmp_4-s_728724756.png
可见,进行了强转,那如果要修改为double 该如何操作呢,FiltersFunctionFactorScorer 继承了FilterScorer
https://s4.运维网.com/wyfs02/M00/97/E9/wKioL1k09zigR385AACfvi9NnB8063.png-wh_500x0-wm_3-wmp_4-s_2997191398.png
而FilterScorer 的包为org.apache.lucene.search,可见是因为lucene 的打分是float,所以elasticsearch 的打分也只能是float,谁让elasticsearch 是基于lucene 的呢。所以你如果要修改分数为double类型,最根源还是要修改lucene 的源代码。网上有人对lucene 做了一个patch,但还没有尝试。地址为:https://issues.apache.org/jira/browse/LUCENE-5596。
我目前用的elasticsearch 的版本是5以下, 或许后续的版本会修复这个问题。
所以如果打分因子范围过亿,恭喜你,分数已经已经不准了。
页:
[1]