【问题标题】:Custom scoring function in Elasticsearch does not return expected field valueElasticsearch 中的自定义评分函数不返回预期的字段值
【发布时间】:2016-06-22 21:25:20
【问题描述】:

我为我的文档创建了一个自定义评分函数,它只返回每个文档的字段 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"
        }
      }
    }
  }
}

这将返回以下内容:

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

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    _score 值在内部被硬编码为浮点数,它只能准确表示不超过 134217728 的整数。因此,如果您想在评分函数中使用存储为大于的数字的字段那,它将溢出缓冲区并被截断。见this github issue

    【讨论】:

      猜你喜欢
      • 2015-03-21
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 2018-12-05
      • 2020-12-23
      相关资源
      最近更新 更多