# Indexing documents with nested fields

**URL:** <https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541>\
**Category:** Elasticsearch\
**Created:** [February 15, 2019, 7:56am UTC](https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541 "2019-02-15T07:56:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikhil\_sharma1](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Nikhil\_sharma1](https://discuss.elastic.co/u/Nikhil_sharma1)\
**Post date:** [February 15, 2019, 7:56am UTC](https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541/1 "2019-02-15T07:56:59Z")

</div>

Hi,

We have setup ELK infra on AWS. I would like to understand is there any limitation from ELK side to the numbers of fields that can be indexed? As, our schema has a Map fields and it has many unique fields in it, the index size is growing and slowing down ELK. Do you have recommendations around that can be done to optimize it? It has been communicated by our infra team that ELK has a limitation of indexing only 1000 unique fields (is it true?)

---

<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 15, 2019, 8:18am UTC](https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541/2 "2019-02-15T08:18:27Z")

</div>

There is indeed a limit on the number of fields. Instead of having many different fields maybe you can create a common schema across all your documents - or index these documents in to different indices instead, where you can have of course differently named fields (again up to 1k).

You may want to take a look at the [elastic common schema](https://github.com/elastic/ecs) for some inspiration.

See more at [https://www.elastic.co/blog/brewing-in-beats-introduce-elastic-common-schema](https://www.elastic.co/blog/brewing-in-beats-introduce-elastic-common-schema)

--Alex

---

<div class="post-metadata">

**Author:** ![Nikhil\_sharma1](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Nikhil\_sharma1](https://discuss.elastic.co/u/Nikhil_sharma1)\
**Post date:** [February 15, 2019, 9:04am UTC](https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541/3 "2019-02-15T09:04:20Z")

</div>

Hi Alexander,  
Thanks for your reply! How to optimize the scenario where I have a nested child json and that json has no schema attached to it! Basically the users can put in any fields that they want in that JSON (its a HashMap\<String,String\>). Is there any recommendation for such kind of data?

---

<div class="post-metadata">

**Author:** ![RahulD](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@RahulD](https://discuss.elastic.co/u/RahulD)\
**Post date:** [February 15, 2019, 8:59pm UTC](https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541/4 "2019-02-15T20:59:54Z")

</div>

You can store the key part of the map inside a nested field called key\_field and the value part of the map in a field called value\_field. Both key\_field and value\_field can have type = keyword. That way the nested document only ever has 2 fields that will save you from your index mapping growing over time.

---

<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 15, 2019, 9:00pm UTC](https://discuss.elastic.co/t/indexing-documents-with-nested-fields/168541/5 "2019-03-15T21:00:03Z")

</div>

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