Elastic mapping improper integer coercion to decimal/float

Input document
{"warrantyMiles":65000,"loadIndex":95}

Index mapping
"loadIndex": { "type": "integer", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "warrantyMiles": { "type": "integer", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }

Search response (current & wrong with decimal part):
{"warrantyMiles": "65000.0", "loadIndex": "95.0"}

Search response (expected without decimal part):
{"warrantyMiles": "65000", "loadIndex": "95"}

Any help is highly appreciated and thanks in advance.

Welcome to our community! :smiley:
In future, it's super useful if you can provide a working example so that people can copy and paste to see if they get the same outcomes.

Here's what I did;

PUT test/_mapping
{
  "properties": {
    "warrantyMiles": {
      "type": "integer"
    },
    "loadIndex": {
      "type": "integer"
    }
  }
}

POST test/_doc/1
{
  "warrantyMiles": 65000,
  "loadIndex": 95
}

GET test/_doc/1
{
  "_index" : "test",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 1,
  "_primary_term" : 5,
  "found" : true,
  "_source" : {
    "warrantyMiles" : 65000,
    "loadIndex" : 95
  }
}

GET test/_search
{
  "took" : 256,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_id" : "AJli2H8BVCqNRUuUrNIe",
        "_score" : 1.0,
        "_source" : {
          "data" : "test"
        }
      },
      {
        "_index" : "test",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "warrantyMiles" : 65000,
          "loadIndex" : 95
        }
      }
    ]
  }
}

Also, you probably don't need the keyword field there.

Hi warkolm,
Appreciate your time & support. Thank you very much.
Still peculiar though, was able to resolve it in a different way. i.e.
the mapping remained same i.e. type: 'integer' but the input document having values in string form "65000" or "95" instead of pure integer form of 65000/95 made to index them as integers and finally give it back in same string form "65000"/"95" though they are indexed as integers, and importantly without the decimal part ".0". However, when an integer is fed directly from input document as 65000/95 as pure integers and if the mapping type is integer then while indexing it is appending ".0" decimal part which is still peculiar for me. May be it is the way it works, not sure. Thanks anyway!

What do you mean by "Search response"?

The _source part should be the same with your input if without some ingest pielines.

In addition, when you add

{"fields": ["warrantyMiles","loadIndex"]}

to the request, you will get integer expression.

Hi Tomo,
I meant "Search response" as the resultant document after search. Case 1 output is something not expected, but Case 2 is acceptable as there is no modification of data type (i.e. addition of decimal part).

Mapping remain same in both cases below

"properties": {
    "warrantyMiles": {
      "type": "integer"
    },
    "loadIndex": {
      "type": "integer"
    }
  }

Case 1:
Input document

{
"warrantyMiles": 65000,
"loadIndex": 95
}

Search output document

{
"warrantyMiles": "65000.0",
"loadIndex": "95.0"
}

Case 2:
Input document

{
"warrantyMiles": "65000",
"loadIndex": "95"
}

Search output document

{
"warrantyMiles": "65000",
"loadIndex": "95"
}

Please clarify the position of the response.
I'm glad if you paste the whole response and the json path to the problematic field.

For example,

{
  "_index" : "test",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 1,
  "_primary_term" : 5,
  "found" : true,
  "_source" : {
    "warrantyMiles" : 65000,
    "loadIndex" : 95
  }
}

is the whole response to GET test/_doc/1.

1 Like

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