# Indexing children before parents - should I be worried?

**URL:** <https://discuss.elastic.co/t/indexing-children-before-parents-should-i-be-worried/106937>\
**Category:** Elasticsearch\
**Created:** [November 8, 2017, 10:21pm UTC](https://discuss.elastic.co/t/indexing-children-before-parents-should-i-be-worried/106937 "2017-11-08T22:21:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua\_Stromme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshua_stromme/32/44982_2.png) [@Joshua\_Stromme](https://discuss.elastic.co/u/Joshua_Stromme)\
**Post date:** [November 8, 2017, 10:21pm UTC](https://discuss.elastic.co/t/indexing-children-before-parents-should-i-be-worried/106937/1 "2017-11-08T22:21:29Z")

</div>

I'm using Elasticsearch 5.3  
Will it cause any issues if a child document is indexed before its parent?  
I've come against a situation where its messy to guarantee that the parent already exists. If the parent doesn't exist, it will most likely be coming in the next bulk insert.

[https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-parent-field.html#\_parent\_child\_restrictions](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-parent-field.html#_parent_child_restrictions) doesn't seem to warn against indexing children first, and I don't see any errors when I try it out.

I'm just worried that the parent might end up on a different shard.

Can anyone shed light on this concern?

Thank you so much!  
Josh

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 10, 2017, 5:39am UTC](https://discuss.elastic.co/t/indexing-children-before-parents-should-i-be-worried/106937/2 "2017-11-10T05:39:01Z")

</div>

As long as you know the parent ID and provide it when you index the child, it's perfectly fine to index a child before the parent. By providing the parent ID when indexing the child, the child is routed to the shard that the parent will also end up on.

---

<div class="post-metadata">

**Author:** ![Joshua\_Stromme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshua_stromme/32/44982_2.png) [@Joshua\_Stromme](https://discuss.elastic.co/u/Joshua_Stromme)\
**Post date:** [November 10, 2017, 6:06am UTC](https://discuss.elastic.co/t/indexing-children-before-parents-should-i-be-worried/106937/3 "2017-11-10T06:06:47Z")

</div>

Fantastic. Saves me a good deal of trouble.  
Thank you!

---

<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 8, 2017, 6:07am UTC](https://discuss.elastic.co/t/indexing-children-before-parents-should-i-be-worried/106937/4 "2017-12-08T06:07:20Z")

</div>

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