# Nested Array in Array

**URL:** <https://discuss.elastic.co/t/nested-array-in-array/134159>\
**Category:** Elasticsearch\
**Created:** [June 1, 2018, 7:37am UTC](https://discuss.elastic.co/t/nested-array-in-array/134159 "2018-06-01T07:37:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktsigkounis](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@ktsigkounis](https://discuss.elastic.co/u/ktsigkounis)\
**Post date:** [June 1, 2018, 7:37am UTC](https://discuss.elastic.co/t/nested-array-in-array/134159/1 "2018-06-01T07:37:35Z")

</div>

Hello all,

I have to index a json to Elastic which look like the below format. My problem is that the key "variable" is array that contains json objects (I thought about "nested" datatype of Elastic) but some of those objects it's possible to contain nested json arrays inside them. (see variable CUSTOMERS).

* * *

POST /example\_data/data  
{

"process\_name": "TEST\_PROCESS",  
"process\_version ": 0,  
"process\_id": "1111",  
"activity\_id": "111",  
"name": "update\_data",  
"username": "testUser",  
"datetime": "2018-01-01 10:00:00",  
"variables": [{  
"name": "ΒΑΝΚ",  
"data\_type": "STRING",  
"value": "EUROBANK"  
},{  
"name": "CITY",  
"data\_type": "STRING",  
"value": "LONDON"  
}, {  
"name": "CUSTOMERS",  
"data\_type": "ENTITY",  
"value": [{  
"variables": [{  
"name": "CUSTOMER\_NAME",  
"data\_type": "STRING",  
"value": "JOHN"  
}, {  
"name": " CUSTOMER\_CITY",  
"data\_type": "STRING",  
"value": "LONDON"  
}  
]  
}  
]  
}, {  
"name": "CUSTOMERS",  
"data\_type": "ENTITY",  
"value": [{  
"variables": [{  
"name": "CUSTOMER\_NAME",  
"data\_type": "STRING",  
"value": "ΑΘΗΝΑ"  
}, {  
"name": " CUSTOMER\_CITY ",  
"data\_type": "STRING",  
"value": "LIVERPOOL"  
}, {  
"name": " CUSTOMER\_NUMBER",  
"data\_type": "STRING",  
"value": "1234567890"  
}

]  
}  
]  
}  
] }

* * *

When I'm trying to index it I get the following error

* * *

{ "error": {  
"root\_cause": [  
{  
"type": "illegal\_argument\_exception",  
"reason": "Can't merge a non object mapping [variables.value] with an object mapping [variables.value]"  
}  
],  
"type": "illegal\_argument\_exception",  
"reason": "Can't merge a non object mapping [variables.value] with an object mapping [variables.value]" }, "status": 400 }

* * *

When I remove the variable CUSTOMERS that contains the array, then It works properly because there are only json objects.

Is there a way to handle that?  
Thanks in advance,  
KT

---

<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:** [June 1, 2018, 7:42am UTC](https://discuss.elastic.co/t/nested-array-in-array/134159/2 "2018-06-01T07:42:10Z")

</div>

Each field in the mapping, e.g. `value` must be mapped to a single type. In your JSON it can be both a string as well as an object, which is not allowed. You will therefore need to restructure your document, e.g. by renaming fields, before you are able to index it into Elasticsearch.

---

<div class="post-metadata">

**Author:** ![ktsigkounis](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@ktsigkounis](https://discuss.elastic.co/u/ktsigkounis)\
**Post date:** [June 1, 2018, 8:31am UTC](https://discuss.elastic.co/t/nested-array-in-array/134159/3 "2018-06-01T08:31:57Z")

</div>

Inside variable with `data_type = ENTITY`, I changed the key `value` with `entity_value`, to avoid conflict. So now value contains text and entity\_values contains object.

With this, I was able to index it properly into Elasticsearch

---

<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:** [June 29, 2018, 8:31am UTC](https://discuss.elastic.co/t/nested-array-in-array/134159/4 "2018-06-29T08:31:58Z")

</div>

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