使用 ElasticSearch 的脚本功能时,我注意到舍入问题。我有以下映射:
{
"my-index": {
"mappings": {
"my-document": {
"properties": {
"id": {
"type": "long"
},
"foo": {
"type": "float"
}
}
}
}
}
}
和一堆被索引的文件。一个文档的值为159944154.8644
forfoo
字段。当我发送以下查询时:
{
"query": {
"bool": {
"must": [
{ "match": { "id": 42 } }
]
}
},
"_source": {
"includes": ["id","foo"]
},
"script_fields": {
"foo_scripted": {
"script": {
"lang": "painless",
"inline": "doc['foo'].value"
}
}
}
}
我得到以下四舍五入的值作为响应:
{
"_index": "my-index",
"_type": "my-document",
"_id": "42",
"_score": 1,
"_source": {
"foo": 1.599441548644E8, //= 159944154.8644 -> correct!
"id": 42
},
"fields": {
"foo_scripted": [
1.5994416E8 //= 159944160.0 -> rounded :(
]
}
}
知道如何解决这个问题吗?提前致谢。
ES 版本:5.3.0