# Elasticsearch 2.4 reject documents that has multiple datatypes in particular value

**URL:** <https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294>\
**Category:** Elasticsearch\
**Created:** [February 21, 2020, 6:03am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294 "2020-02-21T06:03:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shagun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shagun/32/59565_2.png) [@shagun](https://discuss.elastic.co/u/shagun)\
**Post date:** [February 21, 2020, 6:03am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/1 "2020-02-21T06:03:28Z")

</div>

I am using elastic search **2.4** and when I put documents on elasticsearch, the documents that contain **different data types** for some field are rejected by ES. This is because of the mapping I guess. I need to insert all the documents in ES, Is there any way to do that.

**Sample Documents :**

```
{
"key ": {
"key1": 123,
"key2" : "value2"
} } ,

{
"key ": {
"key1": 1234,
"key2" : "value2"
} } ,

{
"key ": {
"key1": "value1",
"key2" : "value2"
} },

{
"key ": {
"key1": "value1",
"key2" : "value2"
} }

```

so, in this case, the first 2 documents are inserted in the ES successfully where the datatype of **key.key1** is of type Integer. In the 3rd and other document the data type of that field is changed to string or may be JSON or other in further documents.  
So it rejects because of **key.key1** is not the type as expected.

Similarly, if I put the 3rd document first in the new index, It will reject the 1st, 2nd and all other documents that contain different data types for a particular field.

So what can I do in this?  
Thanks In advance.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 21, 2020, 7:54am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/2 "2020-02-21T07:54:38Z")

</div>

you can configure the mapping on a per field base to ignore malformed fields, which are then ignored when searched.

---

<div class="post-metadata">

**Author:** ![shagun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shagun/32/59565_2.png) [@shagun](https://discuss.elastic.co/u/shagun)\
**Post date:** [February 21, 2020, 8:17am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/3 "2020-02-21T08:17:24Z")

</div>

Yes, But here I need all the documents in the Index and all fields should be searchable.  
There are no malformed fields, all fields are important and the JSON documents are generated dynamically. so there are data type issue in field.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 21, 2020, 8:34am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/4 "2020-02-21T08:34:06Z")

</div>

you can use a dynamic template to make sure everything is mapped as a string.

---

<div class="post-metadata">

**Author:** ![shagun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shagun/32/59565_2.png) [@shagun](https://discuss.elastic.co/u/shagun)\
**Post date:** [February 21, 2020, 10:19am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/5 "2020-02-21T10:19:49Z")

</div>

Yes,  
I am using dynamic templates and configured the fields that are in String should be considered as Not Analysed.

What should I do in this situation :

```
{
"key ": {
"key1": 1234,
"key2" : "value2"
} } ,

{
"key ": {
"key1": "value1",
"key2" : "value2"
} },
{
"key ": {
"key1": {"key_1": "value","key_2": "value"}
"key2" : "value2"
} }

```

I have sometimes Object in that particular field **key.key1**.  
Here I can not mark this field as String.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 21, 2020, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/6 "2020-02-21T11:26:13Z")

</div>

That you can not index in Elasticsearch if you want all the fields searchable, so you will need to alter the structre. Elasticsearch allows mappings to be dynamically created but is not schema-less.

---

<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:** [March 20, 2020, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-2-4-reject-documents-that-has-multiple-datatypes-in-particular-value/220294/7 "2020-03-20T11:26:20Z")

</div>

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