我想尝试 Elasticsearch 的 scaled_float
但无法理解以下内容:
如果我像文档中那样为我的索引创建一个映射:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"price": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
}
然后我将一些数据添加到索引中,如下所示:
PUT my_index/my_type/1
{
"price" : 100.1599999999
}
我希望得到 100.16
的价格,而不是 GET my_index/my_type/1
的结果显示:
{
"_index": "my_index",
"_type": "my_type",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"price": 100.1599999999
}
}
为什么不是圆的?
或者舍入值只用于索引,我在这里看到的是保存的原始输入,因为它在“_source”下?如何检查舍入是否发生?
我正在使用 Elasticsearch 5.6.5 和 Lucene 6.6.1
提前致谢!
最佳答案
无论您在 _source
中索引什么都不会改变,但是,下方的价格将被索引为 100.16
如果您运行此查询,您将看到 100.16 而不是 100.1599999999
GET my_index/_search
{
"size": 0,
"aggs": {
"avg": {
avg": {
"field": "price"
}
}
}
}
关于elasticsearch - 为什么 Elasticsearch 中的 scaled_float 不四舍五入小数位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55028058/