0

I'm using below query to fetch double value but it is ignoring decimals after dot.

POST gs011_tasks/_search
{
  "from": 0,
  "size": 0,
  "version": true,
  "aggregations": {
   
        "DB_PLOTS": {
          "terms": {
            "script": {
              "source": "doc['area_count']", // this is double value:3.92922
              "lang": "painless"
            }
         
      }
    }
  }
}
Area stored in elastic search is 3.925022
Expected value from above query is 3.925022
Actual value returned is 3

Can you please help me if we need to add any configuration?

Brian Destura
  • 11,487
  • 3
  • 18
  • 34
Ram Prasad
  • 13
  • 2
  • Can you share the mapping of the `area_count` field? – Val Jul 19 '21 at 11:10
  • Hi Val, actually the type is long ,but value stored is 3.925022. I think I need to change the type right ? – Ram Prasad Jul 22 '21 at 03:50
  • Yes absolutely, your type is wrong, probably because the first document you indexed had a long value (or simply 0) and that's why the mapping is long instead of double/float – Val Jul 22 '21 at 04:11

1 Answers1

0

You need to make sure that in your mapping area_count is of type double or float.

The reason you're seeing 3 in the response is probably because currently that field is of type integer or long because the first document you indexed had an area_count value that was an integer value (or simply 0).

Val
  • 207,596
  • 13
  • 358
  • 360
  • Its working after changing the data type to double used below query to change PUT /indexName/_mapping { "properties": { "area1": { "type": "double" }, "area2": { "type": "double" } } } – Ram Prasad Jul 26 '21 at 10:25