Reputation: 139
I have inserted 1 record with large amount in elastic search. The value is 99999999999
I have used below query and it return sum but value is wrong. It return 9.9999997952E10 how can I get accurate data?
{
"size": 0,
"query": {
"match": {
"subscribercompanyid": 40408
}
},
"aggs": {
"invoicedetails": {
"nested": {
"path": "invoicedetails"
},
"aggs": {
"Childe": {
"sum": {
"field" : "invoicedetails.valueinnumeric"
}
}
}
}
}
}
Response
{
"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
}
}
}
}
Upvotes: 1
Views: 635
Reputation: 217254
If you use a double
instead of a float
then it's going to work as you expect:
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"
}
}
}
}
Results =>
{
"aggregations" : {
"total" : {
"value" : 9.9999997952E10
},
"total2" : {
"value" : 9.9999999999E10
}
}
}
Upvotes: 4