elasticsearch打分精度-创新互联

elasticsearch 原文

创新互联公司提供成都网站建设、网站设计、网页设计,成都品牌网站建设广告投放等致力于企业网站建设与公司网站制作,10余年的网站开发和建站经验,助力企业信息化建设,成功案例突破上1000家,是您实现网站建设的好选择.

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 类

elasticsearch 打分精度

看到computeScore 还是double 类型的,但是 return scoreCombiner.combine 却变成了float,

elasticsearch 打分精度

继续看


elasticsearch 打分精度

可见,进行了强转,那如果要修改为double 该如何操作呢,FiltersFunctionFactorScorer 继承了FilterScorer

elasticsearch 打分精度

而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以下, 或许后续的版本会修复这个问题。

所以如果打分因子范围过亿,恭喜你,分数已经已经不准了。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:elasticsearch打分精度-创新互联
转载源于:http://myzitong.com/article/djdocs.html