# Elasticsearch data type

**URL:** <https://discuss.elastic.co/t/elasticsearch-data-type/238517>\
**Category:** Elasticsearch\
**Created:** [June 24, 2020, 3:09pm UTC](https://discuss.elastic.co/t/elasticsearch-data-type/238517 "2020-06-24T15:09:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [June 24, 2020, 3:09pm UTC](https://discuss.elastic.co/t/elasticsearch-data-type/238517/1 "2020-06-24T15:09:16Z")

</div>

I have an index named users and i have a provided a field called user\_id which is int type.The question is it is accepting floating value and string value.This is the index i have created

```auto
PUT /users
{
  "mappings" : {
    "properties": {
      "user_id": {
        "type": "integer"
      }
    }

```

Now here i have provided some values for testing

```auto
POST /users/_doc/1?refresh=wait_for
{
    "user_id" : 12345
}
POST /users/_doc/2?refresh=wait_for
{
    "user_id" : 123456
}
POST /users/_doc/3?refresh=wait_for
{
    "user_id" : "123456"
}
POST /users/_doc/4?refresh=wait_for
{
    "user_id" : 1.234
}

```

It should not accept the value of string type and floating type but it is not acting like that way

---

<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 24, 2020, 11:02pm UTC](https://discuss.elastic.co/t/elasticsearch-data-type/238517/2 "2020-06-24T23:02:51Z")

</div>

It'll accept the string because of the default `coerce` setting - [https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#number-params](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#number-params)

It seems odd that it accepts document 4 in your example though, I dunno why it'd do that, but I will ask someone that knows that a bit better than me.

---

<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 25, 2020, 12:43am UTC](https://discuss.elastic.co/t/elasticsearch-data-type/238517/3 "2020-06-25T00:43:56Z")

</div>

Ok, so the part I forgot that was we store the original value in `_source`, so you see the string or the fraction, but they're stored in the `user_id` field as integers as per the `coerce` setting.

---

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [June 25, 2020, 5:40am UTC](https://discuss.elastic.co/t/elasticsearch-data-type/238517/4 "2020-06-25T05:40:27Z")

</div>

thanks @warkolm

---

<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 23, 2020, 5:40am UTC](https://discuss.elastic.co/t/elasticsearch-data-type/238517/5 "2020-07-23T05:40:38Z")

</div>

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