# Can we link documents (parent) to the documents (child)?

**URL:** <https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089>\
**Category:** Elasticsearch\
**Created:** [January 29, 2020, 11:46pm UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089 "2020-01-29T23:46:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepak643](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak643/32/45940_2.png) [@deepak643](https://discuss.elastic.co/u/deepak643)\
**Post date:** [January 29, 2020, 11:46pm UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/1 "2020-01-29T23:46:12Z")

</div>

I would like to know if two documents can be linked to get the search benefits?

For example:  
I have a child document which is formed from parent document. I do not want to copy the complete document metadata to child so that child is searchable by parent information. If there is a way to link documents, that helps to avoid having redundant data.

I am talking in the range of Million documents here. Any information would be helpful.

Thank you

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2020, 2:59am UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/2 "2020-01-30T02:59:14Z")

</div>

Have a look at [Join datatype | Elasticsearch Guide [7.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/parent-join.html)

> [@deepak643](#):
>
> I do not want to copy the complete document metadata to child

Why don't you want to do that?

---

<div class="post-metadata">

**Author:** ![deepak643](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak643/32/45940_2.png) [@deepak643](https://discuss.elastic.co/u/deepak643)\
**Post date:** [January 30, 2020, 6:09am UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/3 "2020-01-30T06:09:41Z")

</div>

Because there would be 1000's of child documents for one parent. And replicating all this duplicate data across childs is lot of space. And I am talking about Millions of parent documents and Millions of child documents.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2020, 7:10am UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/4 "2020-01-30T07:10:45Z")

</div>

But doing joins has some tradeoff.

My advice:

- try without join, index some million documents and check if disk usage is actually a problem
- if it's really a problem, move to parent/child but understand that it will be slower, will complicate your queries and will consume more heap space.

---

<div class="post-metadata">

**Author:** ![deepak643](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak643/32/45940_2.png) [@deepak643](https://discuss.elastic.co/u/deepak643)\
**Post date:** [January 30, 2020, 6:11pm UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/5 "2020-01-30T18:11:35Z")

</div>

I was also looking for performance impact if we go this way. very helpful information. I will consider your thoughts.

---

<div class="post-metadata">

**Author:** ![linkerc](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@linkerc](https://discuss.elastic.co/u/linkerc)\
**Post date:** [January 30, 2020, 8:01pm UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/6 "2020-01-30T20:01:44Z")

</div>

do a virtual join by yourself with a field.  
Have the parent hold the data and the child doc contains a field say "parent\_id" that holds the "\_id" of the parent.  
That way you search with the result of the child and get the exact doc (parent) via \_id.

---

<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:** [February 27, 2020, 8:16pm UTC](https://discuss.elastic.co/t/can-we-link-documents-parent-to-the-documents-child/217089/7 "2020-02-27T20:16:26Z")

</div>

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