# Implementing a parent-child relationship and changing parent of a child document

**URL:** <https://discuss.elastic.co/t/implementing-a-parent-child-relationship-and-changing-parent-of-a-child-document/277498>\
**Category:** Elasticsearch\
**Created:** [June 30, 2021, 8:41pm UTC](https://discuss.elastic.co/t/implementing-a-parent-child-relationship-and-changing-parent-of-a-child-document/277498 "2021-06-30T20:41:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ViniciusSPaiva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/viniciusspaiva/32/67297_2.png) [@ViniciusSPaiva](https://discuss.elastic.co/u/ViniciusSPaiva)\
**Post date:** [June 30, 2021, 8:41pm UTC](https://discuss.elastic.co/t/implementing-a-parent-child-relationship-and-changing-parent-of-a-child-document/277498/1 "2021-06-30T20:41:39Z")

</div>

Hello,

We need to create a solution able to search for two entities: record and file. Each one has its properties and records can have zero or more files.

Appears to be very simple, but I am finding very difficult to find an easy answer in Elasticsearch.  
After some research, I concluded that I should use join fields to create a parent-child relationship. Then, the first yellow flag is raised: the documentation says that it could have poor performance.

> "The only case where the join field makes sense is if your data contains a one-to-many relationship where one entity significantly outnumbers the other entity"

We have a larger number of files compared to records, but it certainly do not "significantly outnumbers"... But OK... I guess. I am not sure what to expect from this poor performance.

The second yellow flag is that we can change the record of a file. And that can cause the file to go to a different shard? I found a topic saying that I should delete the child and then creating it again with a different parent. Is that really the way to achieve that?

Any help would be greatly appreciated.

---

<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:** [July 1, 2021, 4:22am UTC](https://discuss.elastic.co/t/implementing-a-parent-child-relationship-and-changing-parent-of-a-child-document/277498/2 "2021-07-01T04:22:57Z")

</div>

How frequently are records updated? How many primary shards will your index have?

---

<div class="post-metadata">

**Author:** ![ViniciusSPaiva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/viniciusspaiva/32/67297_2.png) [@ViniciusSPaiva](https://discuss.elastic.co/u/ViniciusSPaiva)\
**Post date:** [July 1, 2021, 9:56pm UTC](https://discuss.elastic.co/t/implementing-a-parent-child-relationship-and-changing-parent-of-a-child-document/277498/3 "2021-07-01T21:56:39Z")

</div>

Records (and files) can change frequently. As for the number of shards, I am not really sure. Sometimes I think of using only one just to be easier to maintain.

NOTE: We already use Elasticsearch today, but the index only have one entity (files).  
Currently, it has 300 GB and 1 shard.

---

<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 29, 2021, 9:56pm UTC](https://discuss.elastic.co/t/implementing-a-parent-child-relationship-and-changing-parent-of-a-child-document/277498/4 "2021-07-29T21:56:48Z")

</div>

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