Elasticsearch 2.4 reject documents that has multiple datatypes in particular value

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.

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

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.

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

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.

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.

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