How to avoid rounding for currency values?

I have loaded a JSON document into Elasticsearch with currency values. When I create a visualization with a sum aggregation each value is rounded down before creating the sum. How to avoid this?

Sample:
1000
1.99

Sum 1000 + 1 = 1001
How can I get 1000 + 1.99 = 1001.99 ?

Hi,

Longs(1000 here) are integers and not floats. So this is something which you need to do when you are adding your data into Elasticsearch. When you are adding your first number - you need to add it formatted as double: https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html

For example:

PUT foo/rocks/0
{
  "num": 1.99
}


PUT foo/rocks/1
{
  "num": 1000.00
}

After if you execute this, you will get:

GET foo/rocks/_search 
{
  "size": 0,
  "_source": {
    "excludes": []
  },
  "aggs": {
    "1": {
      "sum": {
        "field": "num"
      }
    }
  }
}
{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "1": {
      "value": 1001.9900000095367
    }
  }
}


Hope that helps.

Cheers,
Bhavya

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

Building on the answer from Wrong returned Values on simple SUM-Aggregation, I have the following 3 documents in my dataset:

PUT sap-lo-po/_doc/1
{
  "EBELN": "4500017596",
  "EKPO": [
    {
      "NETWR": 149314.2
    }
  ]
}
PUT sap-lo-po/_doc/2
{
  "EBELN": "4500017596",
  "EKPO": [
    {
      "NETWR": 314.1
    }
  ]
}
PUT sap-lo-po/_doc/3
{
  "EBELN": "4500017596",
  "EKPO": [
    {
      "NETWR": 200
    }
  ]
}

I think the visualization based on this data is then correct: