Why integer 1 converted to 1.0 in a string field

Hi all,

This is my first post here, if I post at the wrong place, please let me know. Thank you.

I have an index and one of its field is a string type. The field setting looks like below.

GET /myindex/_mappings
"myfield": {
"type": "string",
"norms": {
"enabled": false
},
"analyzer": "lowercase_keyword" (my analyzer that combines keyword tokenizer and lowercase tokenizer)
}

Then my application indexed a document that contains myfield:1

After the document is indexed, if I ran "GET /myindex/_search?q=(myfield:1)" it says there is no match. But when I ran "GET /myindex/_search?q=(myfield:1.0)" it can find the document that is just indexed and return the doc to me. When looking at the _source. _source does say myfield is 1, not 1.0.

Does anyone know why this happened and how can I fix this to search 1 instead of 1.0?

Thank you

What ES version are you using, and can you please provide the details of your "lowercase_keyword" analyzer. I think the problem could be in it.

The default Standard analyzer used for string field is indexing "1" to "1", and your query "GET /myindex/_search?q=(myfield:1)" will match.

Json represents all numbers as doubles. So passing it as 1 will be parsed into a double, and then converted to a string when indexing.

Yes, this is the cause. Thank you.

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