Elasticsearch中的自定义评分功能不会返回预期的字段值 [英] Custom scoring function in Elasticsearch does not return expected field value

查看:136
本文介绍了Elasticsearch中的自定义评分功能不会返回预期的字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的文档创建一个自定义评分函数,它只是为每个文档返回字段 a 的值。但是由于某些原因,在下面的示例中,结果中 _score 的最后一位数字与 a 为每个文档。这里发生了什么?

  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
}
}
}
}
}
pre>

这将返回以下内容:

  {
take:16,
timed_out:false,
_shards:{
total:5,
success:5,
$$$$$$$$$$$$$$$$ b $ b {
_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

解决方案

_score 值是内部硬编码为浮点数,只能精确地表示整数,直到值为134217728.因此,如果要在得分函数中使用存储为大于那将会溢出缓冲区并被截断。请参阅此github问题


I create a custom scoring function for my documents that just returns the value of the field a for each document. But for some reason, in the example below, the last digits of the _score in the results differ from the last digits of the value of a for each document. What is happening here?

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"
        }
      }
    }
  }
}

That will return the following:

{
  "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
        }
      }
    ]
  }
}

Why is the _score different than the value of the field a?

I'm using Elasticsearch 2.1.1

解决方案

The _score value is internally hard coded as a float which can only accurately represent integers up to the value 134217728. Therefore, if you want to make use, in the scoring function, of a field stored as a number larger than that, it will overflow the buffer and be truncated. See this github issue

这篇关于Elasticsearch中的自定义评分功能不会返回预期的字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆