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

**URL:** https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745
**Category:** Elastic Search
**Created:** [October 14, 2024, 1:51am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745 "2024-10-14T01:51:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![luoczeng](https://avatars.discourse-cdn.com/v4/letter/l/e8c25b/32.png) [@luoczeng](https://discuss.elastic.co/u/luoczeng)
#### Post date: [October 14, 2024, 1:51am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745/1 "2024-10-14T01:51:40Z")

</div>

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:

```auto
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:

```auto
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...

```auto
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!

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 14, 2024, 5:27am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745/2 "2024-10-14T05:27:30Z")

</div>

Welcome!

If you want to disable this behavior, you need to set coerce to false. See [coerce | Elasticsearch Guide [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/coerce.html)

---

<div class="post-metadata">

### Author: ![luoczeng](https://avatars.discourse-cdn.com/v4/letter/l/e8c25b/32.png) [@luoczeng](https://discuss.elastic.co/u/luoczeng)
#### Post date: [October 14, 2024, 7:43am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745/3 "2024-10-14T07:43:16Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 14, 2024, 11:38am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745/4 "2024-10-14T11:38:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![luoczeng](https://avatars.discourse-cdn.com/v4/letter/l/e8c25b/32.png) [@luoczeng](https://discuss.elastic.co/u/luoczeng)
#### Post date: [October 15, 2024, 2:41am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745/5 "2024-10-15T02:41:24Z")

</div>

Thank you still!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 12, 2024, 2:41am UTC](https://discuss.elastic.co/t/why-es-allow-indexing-numerical-values-with-double-quotes-when-field-type-is-set-to-double-and-dynamic-mapping-is-off-strict/368745/6 "2024-11-12T02:41:51Z")

</div>

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