Hi folks,
I was having a question recently that why ES would allow indexing numerical values with double quotes, when field type is set to double and dynamic mapping is off (strict)?
Below are my dummy index settings:
PUT http://localhost:9200/test_index
Content-type: application/json
Accept: application/json
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"dynamic": "strict",
"properties": {
"field1": { "type": "text" },
"doubleField": { "type": "double" }
}
}
}
I can index documents successfully when 'doubleField' is really a double:
POST http://localhost:9200/test_index/_doc/
Content-type: application/json
Accept: application/json
{
"field1": "random string",
"doubleField": 1.234
}
However I can also index documents when 'doubleField' is wrapped inside quotes...
POST http://localhost:9200/test_index/_doc/
Content-type: application/json
Accept: application/json
{
"field1": "random string",
"doubleField": "1.234"
}
The issue is, when I try to use Elasticsearch NEST library to read the data, I'll have exception complaining string cannot be interpreted as double due to the double quotes.
I know I should fix the index so everything comes into ES is correct, but there are quite a lot of historical data that already have double quotes...
So my questions are:
- are there some secret switches I can turn on to prevent indexing double values with quotes into double fields?
- are there special configurations of the NEST library to auto convert the quoted double strings into numerical double values for me automatically? (writing a special JsonConverter is the last thing I want to do for this...)
Thanks very much!