ElasticSearch Script 查询忽略双精度值中的小数

问题描述

我正在使用下面的查询获取双精度值,但它忽略了点后的小数。

POST gs011_tasks/_search
{
  "from": 0,"size": 0,"version": true,"aggregations": {
   
        "DB_PLOTS": {
          "terms": {
            "script": {
              "source": "doc['area_count']",// this is double value:3.92922
              "lang": "painless"
            }
         
      }
    }
  }
}
Area stored in elastic search is 3.925022
Expected value from above query is 3.925022
Actual value returned is 3

如果我们需要添加任何配置,你能帮我吗?

解决方法

您需要确保在您的映射中 area_count 的类型为 doublefloat

您在响应中看到 3 的原因可能是因为当前该字段的类型为 integerlong,因为您索引的第一个文档的 area_count 值是整数值(或简单的 0)。