Why ES allow indexing numerical values with double quotes, when field type is set to double and dynamic mapping is off (strict)?

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:

  1. are there some secret switches I can turn on to prevent indexing double values with quotes into double fields?
  2. 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!

Welcome!

If you want to disable this behavior, you need to set coerce to false. See coerce | Elasticsearch Guide [8.15] | Elastic

Thank you very much for this tip!
Can you suggest how I should config the json serializer to be able to automatically convert from "1.0" to 1 for an integer field, using NEST 7.17.5 ?

No. I don't know anything about Nest I'm afraid :slight_smile:

Thank you still!