# Optional parent field for child documents?

**URL:** <https://discuss.elastic.co/t/optional-parent-field-for-child-documents/15961>\
**Category:** Elasticsearch\
**Created:** [February 21, 2014, 10:22pm UTC](https://discuss.elastic.co/t/optional-parent-field-for-child-documents/15961 "2014-02-21T22:22:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_D\_Moffitt](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Michael\_D\_Moffitt](https://discuss.elastic.co/u/Michael_D_Moffitt)\
**Post date:** [February 21, 2014, 10:22pm UTC](https://discuss.elastic.co/t/optional-parent-field-for-child-documents/15961/1 "2014-02-21T22:22:05Z")

</div>

Hello,

I'm trying to create parent/child relationships between documents that are  
all of the same type. This seems to be working OK, except that to enable  
routing, I have to give "top-level" docs a bogus parent (currently ID 0):

```
 https://gist.github.com/mmoffitt/9144694

```

Can I somehow omit parent and have it use the child's ID instead? More  
importantly, are there more serious problems here, since each child's  
parent will be routed based the grandparent's ID (and not its own)?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1205fba8-7b35-40e6-891a-1f729e0a7216%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1205fba8-7b35-40e6-891a-1f729e0a7216%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 22, 2014, 3:04am UTC](https://discuss.elastic.co/t/optional-parent-field-for-child-documents/15961/2 "2014-02-22T03:04:04Z")

</div>

You might be interested in this where Zach talks about multi-level  
parent-child and how to use routing for those cases:

> **[Customizing Your Document Routing
	  	 | Elastic](https://www.elastic.co/blog/customizing-your-document-routing)**
>
> In this article, we are going to take a look at Elasticsearch’s Routing feature. We’ll discuss what routing is and why you might consider using a non-default routing scheme. What is Routing? All of yo...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ca3e51aa-471b-4c3a-b3c2-e1b937f5b8cb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ca3e51aa-471b-4c3a-b3c2-e1b937f5b8cb%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Karol\_Gwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karol_gwaj/32/1324_2.png) [@Karol\_Gwaj](https://discuss.elastic.co/u/Karol_Gwaj)\
**Post date:** [February 22, 2014, 4:04am UTC](https://discuss.elastic.co/t/optional-parent-field-for-child-documents/15961/3 "2014-02-22T04:04:57Z")

</div>

BTW, i will suggest you to avoid using parent/child relationships if your  
index contains more than million documents per shard  
besides the obvious problems with maintaining parent/child/grandchild  
relationships, parent/child queries tend to be quite slow and id\_cache  
(used to store parent/child ids) will consume a lot of java heap space

On Friday, February 21, 2014 10:22:05 PM UTC, Michael D. Moffitt wrote:

> Hello,
> 
> I'm trying to create parent/child relationships between documents that are  
> all of the same type. This seems to be working OK, except that to enable  
> routing, I have to give "top-level" docs a bogus parent (currently ID 0):
> 
> ```
> https://gist.github.com/mmoffitt/9144694
> 
> ```
> 
> Can I somehow omit parent and have it use the child's ID instead? More  
> importantly, are there more serious problems here, since each child's  
> parent will be routed based the grandparent's ID (and not its own)?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/71cbb9aa-39ff-4a7d-bdcc-bc48c03d7429%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71cbb9aa-39ff-4a7d-bdcc-bc48c03d7429%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:48am UTC](https://discuss.elastic.co/t/optional-parent-field-for-child-documents/15961/4 "2017-07-06T01:48:10Z")

</div>


