Number precision for 22 digit plus 6 digit decimal

We've a requirement to store and fetch a BigDecimal value (22digits + 6 decimals) in elasticsearch field.

While fetching this below field, We're getting value as exponential notation.

We would need it as we posted in body. Need help if there is a setting to avoid this e (scientific notation).

MoreDetails:

  • We're using Java 11 and Jackson dependency
  • This is a BigDecimal datatype working fine when we write this to a json file, issue is with index insertion only
{
"FixedAmount": {
"$":1234567890123456789012.000193,
"@currencyCode":"EUR"
}
}

image

Hello @satyarajpc,

Welcome to the community!

We don't support BigDecimal data type. Just so you know, there have been some discussions about supporting BigDecimal in this issue. But, have you thought about mapping this field as a 'keyword'?

Elasticsearch works better with numeric fields such as integer or long for range queries. However, if you need to perform term and other term-level queries, and fast retrieval is important, keyword fields are the way to go.

PUT /test
{
  "mappings": {
    "properties": {
      "FixedAmount": {
        "type": "keyword"
      }
    }
  }
}
PUT /test/_doc/1
{
  "FixedAmount": "1234567890123456789012.000193"
}

GET /test/_doc/1

Response:

{
  "_index": "test",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "FixedAmount": "1234567890123456789012.000193"
  }
}

Hope it helps!

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