3

I'm using Elasticsearch 2.4. After declaration of index template with one interger field:

curl -XPUT 'localhost:9201/_template/template_1?pretty' -d'
{
  "template": "te*",
  "mappings": {
    "type1": {
      "properties": {
        "aaa": {
          "type": "integer"
        }
      }
    }
  }
}
'

and putting to this index a document with number as string:

curl -XPUT 'localhost:9201/template_1/type1/1?pretty' -d'
{
    "aaa" : "3"
}
'

I receive as a search result:

curl -XGET 'http://localhost:9201/template_1/_search?pretty=true?q=*:*'
...
    "hits" : {
        "total" : 1,
        "max_score" : 1.0,
        "hits" : [ {
          "_index" : "template_1",
          "_type" : "type1",
          "_id" : "1",
          "_score" : 1.0,
          "_source" : {
            "aaa" : "3"
          }
        } ]
      }

Why aaa field is not printed as integer (without quotes) as declared in index template? This field is definitely integer because when I try to assign some characters to aaa there is an exception. But this search result looks confusing and I don't know if Elasticsearch made there implicit conversion to integer or not.

1 Answer 1

2

_source field contains raw document. During processing Elasticsearch automatically converts the field's value to integer and then index. Thus the index contains integer representation of the value whereas raw document contains string value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.