# Index mapping for objects of variable depths

**URL:** <https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253>\
**Category:** Elasticsearch\
**Created:** [March 3, 2017, 3:53am UTC](https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253 "2017-03-03T03:53:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![afrozl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afrozl/32/26197_2.png) [@afrozl](https://discuss.elastic.co/u/afrozl)\
**Post date:** [March 3, 2017, 3:53am UTC](https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253/1 "2017-03-03T03:53:53Z")

</div>

How would I go about indexing a document that contain objects of variable depth such as:

{ fields: {  
args: {  
0: 'one',  
1: 'two',  
2: 'three'  
}  
)  
}  
or  
{ fields: {  
args: {  
0: 'one',  
1: 'two',  
2: { 'param': 'three' }  
}  
)  
}

The situation I have is that if the first type of document gets processed first, the field 'fields.args.2' gets set to text and then the next document doesn't get indexed. Is there a away to handle this or am I missing something?

---

<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:** [March 3, 2017, 6:15am UTC](https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253/2 "2017-03-03T06:15:05Z")

</div>

Each field in an index must have the same mapping across all documents, so having a field be mapped as a string as well as an object is not allowed. If you want these documents in the same index, I believe you will need to alter the structure of the data, e.g. by renaming field based on the type it holds.

---

<div class="post-metadata">

**Author:** ![afrozl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afrozl/32/26197_2.png) [@afrozl](https://discuss.elastic.co/u/afrozl)\
**Post date:** [March 3, 2017, 2:42pm UTC](https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253/3 "2017-03-03T14:42:35Z")

</div>

Thats what I figured. I guess that's why most people insert logstash in the pipeline when ingesting log data

---

<div class="post-metadata">

**Author:** ![afrozl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afrozl/32/26197_2.png) [@afrozl](https://discuss.elastic.co/u/afrozl)\
**Post date:** [March 3, 2017, 9:48pm UTC](https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253/4 "2017-03-03T21:48:41Z")

</div>

I ended up flattening the field and that works fine for my pupose - ie I can still query by individual attributes of nested objects.

The document now looks like:

{ fields: {  
args: {  
0: 'one',  
1: 'two',  
'2/param': 'three'  
}  
)  
}

---

<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 31, 2017, 9:49pm UTC](https://discuss.elastic.co/t/index-mapping-for-objects-of-variable-depths/77253/5 "2017-03-31T21:49:00Z")

</div>

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