# Elastic mapping improper integer coercion to decimal/float

**URL:** <https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165>\
**Category:** Elasticsearch\
**Created:** [June 14, 2022, 1:33pm UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165 "2022-06-14T13:33:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![VenkateshD](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@VenkateshD](https://discuss.elastic.co/u/VenkateshD)\
**Post date:** [June 14, 2022, 1:33pm UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/1 "2022-06-14T13:33:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 14, 2022, 11:01pm UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/2 "2022-06-14T23:01:28Z")

</div>

Welcome to our community! 😃  
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;

```auto
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.

---

<div class="post-metadata">

**Author:** ![VenkateshD](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@VenkateshD](https://discuss.elastic.co/u/VenkateshD)\
**Post date:** [June 17, 2022, 10:49am UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/3 "2022-06-17T10:49:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 20, 2022, 6:06am UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/4 "2022-06-20T06:06:16Z")

</div>

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

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

```

to the request, you will get integer expression.

---

<div class="post-metadata">

**Author:** ![VenkateshD](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@VenkateshD](https://discuss.elastic.co/u/VenkateshD)\
**Post date:** [June 20, 2022, 3:01pm UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/5 "2022-06-20T15:01:15Z")

</div>

> [@VenkateshD](#):
>
> Search response

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

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

```

Case 1:  
Input document

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

```

Search output document

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

```

Case 2:  
Input document

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

```

Search output document

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

```

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 20, 2022, 3:26pm UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/6 "2022-06-20T15:26:42Z")

</div>

> [@VenkateshD](#):
>
> the resultant document after search

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,

```auto
{
  "_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`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 18, 2022, 3:27pm UTC](https://discuss.elastic.co/t/elastic-mapping-improper-integer-coercion-to-decimal-float/307165/7 "2022-07-18T15:27:18Z")

</div>

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