# A Question on whether to use a Nested Datatype

**URL:** <https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394>\
**Category:** Elasticsearch\
**Created:** [November 18, 2019, 10:07pm UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394 "2019-11-18T22:07:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew.whill](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@matthew.whill](https://discuss.elastic.co/u/matthew.whill)\
**Post date:** [November 18, 2019, 10:07pm UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394/1 "2019-11-18T22:07:28Z")

</div>

Hello All.

I wanted to ask for peoples thoughts around whether to use nested datatypes in a particular scenario.

**The scenario:**

I am wanting to store into an index the contents of files and each file contains references to email addresses (along with other textual content). I am (using regex) extracting all the email addresses as I want to perform aggregation queries on these addresses. For each email address I am storing the actual email address in a field, the domain in a field and the pre @ name (e.g. "bob" from "[bob@email.com](mailto:bob@email.com)") in a field (so the email object has 3 fields).

Now there may be 1000s of email addresses in a file I am indexing. I can store the email address details into a nested datatype to the index which the document is being indexed however, I have noted that elastic does place limitations on the number of nested objects that can be stored into a single document (index.mapping.nested\_objects.limit). Alternatively, I can create a separate index to store the email address objects and include a field which stores the ID of the document which contains the file I indexed. However, it is my understanding that the nested datatype is in essence already doing something very similar behind the scenes.

**The question:**

So my question (after all that), do I go with the nested datatype approach and simply increase the limit (index.mapping.nested\_objects.limit) to something "crazy" or do I go with the manual approach of managing a separate index?

Thanks in advance for the advice.

Matt

---

<div class="post-metadata">

**Author:** ![Mikhail\_Khludnev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_khludnev/32/59591_2.png) [@Mikhail\_Khludnev](https://discuss.elastic.co/u/Mikhail_Khludnev)\
**Post date:** [November 19, 2019, 5:24am UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394/2 "2019-11-19T05:24:53Z")

</div>

Hello, Matthew.  
It sounds like you can not bother about nested. Those three field should be sufficient for the associated emails.

---

<div class="post-metadata">

**Author:** ![matthew.whill](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@matthew.whill](https://discuss.elastic.co/u/matthew.whill)\
**Post date:** [November 21, 2019, 2:43am UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394/3 "2019-11-21T02:43:43Z")

</div>

Sorry Mikhail - just confirming. You are saying that I am better to NOT use NESTED DATATYPES and to instead go with a separate index that I manage?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [November 21, 2019, 7:49am UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394/4 "2019-11-21T07:49:10Z")

</div>

I’ve shared this flowchart before to help with the decision process for nested:

> [@Indexing Hierarchical Couchbase Documents](https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400/2):
>
> From the example documents you supplied there's no indication that doc 2 should be related to doc 1. You have 3 options : Collapse all source docs into a single "flat" JSON doc Collapse all source docs into a single "nested" JSON doc [1] Store parent and child source docs separately but relate them when you add them [2] The decision process for why you would choose one approach over another is roughly this: I'm unfamiliar with the couchbase plugin and to what extent it can be made…

---

<div class="post-metadata">

**Author:** ![Mikhail\_Khludnev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_khludnev/32/59591_2.png) [@Mikhail\_Khludnev](https://discuss.elastic.co/u/Mikhail_Khludnev)\
**Post date:** [November 21, 2019, 8:36pm UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394/6 "2019-11-21T20:36:46Z")

</div>

better to NOT use NESTED DATATYPES and get alone with three fields.

---

<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:** [December 19, 2019, 8:36pm UTC](https://discuss.elastic.co/t/a-question-on-whether-to-use-a-nested-datatype/208394/7 "2019-12-19T20:36:48Z")

</div>

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