Elasticsearch data type

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

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

Now here i have provided some values for testing

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

It'll accept the string because of the default coerce setting - 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.

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.

thanks @warkolm

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