# Unable to Index document for array of any data (string, object, array) together

**URL:** <https://discuss.elastic.co/t/unable-to-index-document-for-array-of-any-data-string-object-array-together/195702>\
**Category:** Elasticsearch\
**Created:** [August 19, 2019, 8:33am UTC](https://discuss.elastic.co/t/unable-to-index-document-for-array-of-any-data-string-object-array-together/195702 "2019-08-19T08:33:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debashis\_Mondal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debashis_mondal/32/52537_2.png) [@Debashis\_Mondal](https://discuss.elastic.co/u/Debashis_Mondal)\
**Post date:** [August 19, 2019, 8:33am UTC](https://discuss.elastic.co/t/unable-to-index-document-for-array-of-any-data-string-object-array-together/195702/1 "2019-08-19T08:33:57Z")

</div>

Hi,  
I am using ES-7.x, facing issue while indexing document, the data structure is like below

{  
"field1": [  
"string"  
"object"  
"array"  
]  
}

I am using field type "nested" at the time of index creation

**Note:** If I add the first document like the array of an object and second document is an array of a string, then unable to add the second document.  
Also, I have tried with the field type "text" still getting the same error

Please suggest me, how can I add all type of documents in a single field

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [August 19, 2019, 9:26am UTC](https://discuss.elastic.co/t/unable-to-index-document-for-array-of-any-data-string-object-array-together/195702/2 "2019-08-19T09:26:43Z")

</div>

Unfortunately this is not really supported and will yield all sort of issues. All collections in a document must be of the same type for the entries within it. For instance:

```json
{
  "field1": ["strings"],
  "field2": ["arrays"],
  "field3": ["objects"]
}

```

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [August 19, 2019, 10:05am UTC](https://discuss.elastic.co/t/unable-to-index-document-for-array-of-any-data-string-object-array-together/195702/3 "2019-08-19T10:05:00Z")

</div>

Just a note, you can do it if you disable indexing, but then nothing will be searchable or aggrageatable.

One workaround is doing what kibana does for it's objects which is wrapping the value in a object:

```json
[
  { "type": "string", "string": "string_value" },
  { "type": "array', "array": "array_value" }
]

```

This way you can also index without issues

---

<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:** [September 16, 2019, 10:05am UTC](https://discuss.elastic.co/t/unable-to-index-document-for-array-of-any-data-string-object-array-together/195702/4 "2019-09-16T10:05:06Z")

</div>

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