elasticsearchelasticsearch-scripting

ElasticSearch Script query is ignoring decimals from double value


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?


Solution

  • 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).