Elasticsearch indexing wrong value for double fields

Hello,

I'm facing some issues indexing double fields without quotation marks.

PUT test
{
    "mappings" : {
        "type1" : {
            "properties" : {
                "field1" : { "type" : "double" }
            }
        }
    }
}

POST test/type1/1
{
  "field1": 15414001497201083
}

GET test/type1/1

{
  "_index": "test",
  "_type": "type1",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "field1": 15414001497201084
  }
}

When using quotation marks it works as expected:

POST test/type1/1
{
  "field1": "15414001497201083"
}

GET test/type1/1

{
  "_index": "test",
  "_type": "type1",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "field1": "15414001497201083"
  }
}

Is it necessary to use quotation marks to index double fields?

Elasticsearch version: 5.5.1

Thank you,
LG

You did not specify what client you are using yet I suspect that that is the problem here. I think that you are using a JavaScript-based client (e.g., Console). The problem is that everything in JavaScript is a IEEE-754 double and 15414001497201083 can not be represented exactly in that representation, the nearest number that can be represented is 15414001497201084 (see this calculator) for example. Therefore, your client is making this conversion before sending the input to Elasticsearch. You could see this if you tcpdump the HTTP request to Elasticsearch. If you use say curl which is not going to do such a conversion before sending the request to Elasticsearch, you will instead see what you expect.

2 Likes

Hi @jasontedor you've got the point. First I was using NEST and then tried Console. Using curl it doesn't happen.

Thank you!

You are very welcome.

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