我在 flex 搜索中插入了大量1条记录。值是99999999999
我用下面的查询,它返回总和,但值是错误的。返回9.9999997952E10如何获取准确的数据?
{
"size": 0,
"query": {
"match": {
"subscribercompanyid": 40408
}
},
"aggs": {
"invoicedetails": {
"nested": {
"path": "invoicedetails"
},
"aggs": {
"Childe": {
"sum": {
"field" : "invoicedetails.valueinnumeric"
}
}
}
}
}
}
响应
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.0,
"hits": []
},
"aggregations": {
"invoicedetails": {
"doc_count": 1,
"Childe": {
"value": 9.9999997952E10
}
}
}
}
最佳答案
如果您使用的是double
而不是float
,那么它将按预期工作:
PUT test
{
"mappings": {
"doc": {
"properties": {
"total": {
"type": "float"
},
"total2": {
"type": "double"
}
}
}
}
}
PUT test/doc/1
{
"total": 99999999999,
"total2": 99999999999
}
POST test/_search
{
"size": 0,
"aggs": {
"total": {
"sum": {
"field": "total"
}
},
"total2": {
"sum": {
"field": "total2"
}
}
}
}
结果=>
{
"aggregations" : {
"total" : {
"value" : 9.9999997952E10
},
"total2" : {
"value" : 9.9999999999E10
}
}
}