# Its about parent-child relationship

**URL:** https://discuss.elastic.co/t/its-about-parent-child-relationship/36837
**Category:** Elasticsearch
**Created:** [December 10, 2015, 7:04am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837 "2015-12-10T07:04:36Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 10, 2015, 7:04am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/1 "2015-12-10T07:04:36Z")

</div>

can we have multiple child for a same parent relationship in elasticsearch ?? or can a single parent document have multiple child document ??

---

<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: [December 10, 2015, 7:38am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/2 "2015-12-10T07:38:17Z")

</div>

a child can have only one parent  
a parent can have 0-n children

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 10, 2015, 9:20am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/3 "2015-12-10T09:20:07Z")

</div>

how do we obtain relationship of one parent with 'n' number of children

---

<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: [December 10, 2015, 9:20am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/4 "2015-12-10T09:20:53Z")

</div>

You index n documents with `parent=the_parent_doc_id`.

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 10, 2015, 9:21am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/5 "2015-12-10T09:21:37Z")

</div>

can it be in detain i didn't get it

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 10, 2015, 9:30am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/6 "2015-12-10T09:30:19Z")

</div>

can it be explained in detaili i didn't get it

---

<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: [December 10, 2015, 9:39am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/7 "2015-12-10T09:39:35Z")

</div>

May be I did not get your question?

Have a look at docs here: [https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html?q=Parent%20child](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html?q=Parent%20child)

If you still don't understand, may be you could explain with some examples what you are doing?

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 10, 2015, 9:52am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/8 "2015-12-10T09:52:41Z")

</div>

ya i got the link which u had sent.... but my doubt is for example i have places as the index name  
and under that i have types to be restaurants and parks. In turn these two will have individual documents inside with different id's.

![](https://us1.discourse-cdn.com/elastic/original/2X/e/ec8531ee0a3dc39d2cdf0f6eb4bd1074cd9c3cc9.png)

How can I make ‘places’ to be parent for both ‘restaurants’ child and ‘parks’ child document as well.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [December 12, 2015, 12:52am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/9 "2015-12-12T00:52:46Z")

</div>

Places cannot be an index if that is what you want to do.  
You will need a places document, with parks/restaurants as the children.

But that doesn't really make a lot of sense to me.

---

<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: [December 12, 2015, 7:27am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/10 "2015-12-12T07:27:09Z")

</div>

Parent-Child can be very useful if you have a parent entity that gets updated frequently and you want to avoid having to update this data on every child entity. In your case it sounds like the data is quite states, so it may be worthwhile considering denormalising it instead, which gives a flatter model that in many cases tend to scale and perform better.

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 15, 2015, 3:47am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/11 "2015-12-15T03:47:41Z")

</div>

Ya i got it 'places' should be 'type' and cannot be 'index'.  
My doubt was how to create a parent child relationship if i have places as the parent document and child documents to be restaurants, parks and the theaters. how do i map all these documents

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 15, 2015, 6:13am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/12 "2015-12-15T06:13:44Z")

</div>

![](https://us1.discourse-cdn.com/elastic/original/2X/e/e73b42803cb16e139f16d5c9ab98ef2e1bcd3a99.png)

How can i map the parent document with 3 child documents.

---

<div class="post-metadata">

### Author: ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)
#### Post date: [December 15, 2015, 9:27am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/13 "2015-12-15T09:27:14Z")

</div>

Reading through the thread it seems to me like we should take a step back actually and first understand what exactly you want to do with these documents once they are indexed:

- What types of queries do you want to execute against the finished index?
- What types of updates will have to be applied to your documents, if any?

Isabel

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [December 16, 2015, 8:35am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/14 "2015-12-16T08:35:03Z")

</div>

I want to perform union operation considering those documents. i.e. by using 'OR' operator

---

<div class="post-metadata">

### Author: ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)
#### Post date: [December 16, 2015, 9:14am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/15 "2015-12-16T09:14:43Z")

</div>

Hmm - I still don't get the full picture. Maybe it helps if you add a more detailed example? Leave out the technical details for now and focus just on the use case. Something along the lines of: "A user wants to know which parks and restaurants are close to their location."

If this requests sounds weird, here's why I'm asking: "Your question appears to be an "XY Problem" ... that is: you are dealing with "X", you are assuming "Y" will help you, and you are asking about "Y" without giving more details about the "X" so that we can understand the full issue. Perhaps the best solution doesn't involve "Y" at all? See Also: [http://www.perlmonks.org/index.pl?node\_id=542341](http://www.perlmonks.org/index.pl?node_id=542341)" (Disclaimer taken from [https://home.apache.org/~hossman/#xyproblem](https://home.apache.org/~hossman/#xyproblem) )

Isabel

---

<div class="post-metadata">

### Author: ![Somnath\_Shantveer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/somnath_shantveer/32/10084_2.png) [@Somnath\_Shantveer](https://discuss.elastic.co/u/Somnath_Shantveer)
#### Post date: [June 16, 2016, 6:49pm UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/16 "2016-06-16T18:49:07Z")

</div>

I hope Kruthika got answer for her question by now.  
If i understand the question correctly, I think you need the mapping file to map "places" to three different type of children.

```
> post http://localhost:9200/sys
> {
> "mappings": {
> "places" : {},
> "parks" : {
> "_parent" : {
> "type" : "places"
> }
> },
> "restaurants" : {
> "_parent" : {
> "type" : "places"
> }
> },
> "theaters" : {
> "_parent" : {
> "type" : "places"
> }
> }
> }
> }
```

---

<div class="post-metadata">

### Author: ![Kruthika](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kruthika](https://discuss.elastic.co/u/Kruthika)
#### Post date: [June 17, 2016, 2:50am UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/17 "2016-06-17T02:50:53Z")

</div>

ya 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: [July 5, 2017, 10:43pm UTC](https://discuss.elastic.co/t/its-about-parent-child-relationship/36837/18 "2017-07-05T22:43:00Z")

</div>


