# Is there any way to emulate a "has\_parent" type of functionality?

**URL:** https://discuss.elastic.co/t/is-there-any-way-to-emulate-a-has-parent-type-of-functionality/5803
**Category:** Elasticsearch
**Created:** [November 8, 2011, 1:45am UTC](https://discuss.elastic.co/t/is-there-any-way-to-emulate-a-has-parent-type-of-functionality/5803 "2011-11-08T01:45:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jim](https://discuss.elastic.co/u/Jim)
#### Post date: [November 8, 2011, 1:45am UTC](https://discuss.elastic.co/t/is-there-any-way-to-emulate-a-has-parent-type-of-functionality/5803/1 "2011-11-08T01:45:34Z")

</div>

Hello,

First off, thank you so much for creating this amazing indexing  
platform. I am enjoying it so far and would like to use it on a  
project I am on.

Secondly, I searched this group and couldn't find anyone else asking  
about this, so I am sorry in advanced if this has been asked before.

The situation I have right now is I have two types: episode and  
story. Episodes are parents to stories.

I want to run a query on stories, filtered or queried based on content  
on the Episode.

For instance:

Episode -  
Date: 01/01/2011  
Newscaster: Bob Jones

Story (child of episode) -  
Segment number: 1

I want to write a query that will return all stories who have a parent  
episode that has the Newscaster "Bob Jones". Is there any way to do  
this? My alternate option if I cannot is to store some Episode  
content in the Story index so I can get the results I want, but  
ideally I would like to keep them in their own types and query them  
via that parent/child relationship.

I know "has\_child" finds a parent's children that match a specific  
query, but I wanted to see if there was a way to build this  
"has\_parent" type of functionality that would find all children whose  
parents match a specific query.

Any idea if this is currently possible?

Thanks,  
Jim

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [November 8, 2011, 7:26am UTC](https://discuss.elastic.co/t/is-there-any-way-to-emulate-a-has-parent-type-of-functionality/5803/2 "2011-11-08T07:26:53Z")

</div>

If you index the parent\_id or even parents' 'Newscaster' (requires  
some more storage+RAM) in the childs too, then its a simple filter  
query ala "type:story AND parent\_newcaster:'Bob Jones'"

Peter.

On Nov 8, 2:45 am, Jim [schm...@gmail.com](mailto:schm...@gmail.com) wrote:

> Hello,
> 
> First off, thank you so much for creating this amazing indexing  
> platform. I am enjoying it so far and would like to use it on a  
> project I am on.
> 
> Secondly, I searched this group and couldn't find anyone else asking  
> about this, so I am sorry in advanced if this has been asked before.
> 
> The situation I have right now is I have two types: episode and  
> story. Episodes are parents to stories.
> 
> I want to run a query on stories, filtered or queried based on content  
> on the Episode.
> 
> For instance:
> 
> Episode -  
> Date: 01/01/2011  
> Newscaster: Bob Jones
> 
> Story (child of episode) -  
> Segment number: 1
> 
> I want to write a query that will return all stories who have a parent  
> episode that has the Newscaster "Bob Jones". Is there any way to do  
> this? My alternate option if I cannot is to store some Episode  
> content in the Story index so I can get the results I want, but  
> ideally I would like to keep them in their own types and query them  
> via that parent/child relationship.
> 
> I know "has\_child" finds a parent's children that match a specific  
> query, but I wanted to see if there was a way to build this  
> "has\_parent" type of functionality that would find all children whose  
> parents match a specific query.
> 
> Any idea if this is currently possible?
> 
> Thanks,  
> Jim

---

<div class="post-metadata">

### Author: ![Jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jim](https://discuss.elastic.co/u/Jim)
#### Post date: [November 8, 2011, 2:59pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-emulate-a-has-parent-type-of-functionality/5803/3 "2011-11-08T14:59:53Z")

</div>

Thank you for your response!

That is what I plan on doing in case there is no other way to query  
children based on criteria for the parent without duplicating the  
content in the index.

I am just trying to avoid putting parent information on the child, but  
if it is not possible at the moment that is okay.

Thanks,  
Jim

On Nov 8, 2:26 am, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> If you index the parent\_id or even parents' 'Newscaster' (requires  
> some more storage+RAM) in the childs too, then its a simple filter  
> query ala "type:story AND parent\_newcaster:'Bob Jones'"
> 
> Peter.
> 
> On Nov 8, 2:45 am, Jim [schm...@gmail.com](mailto:schm...@gmail.com) wrote:
> 
> > Hello,
> 
> > First off, thank you so much for creating this amazing indexing  
> > platform. I am enjoying it so far and would like to use it on a  
> > project I am on.
> 
> > Secondly, I searched this group and couldn't find anyone else asking  
> > about this, so I am sorry in advanced if this has been asked before.
> 
> > The situation I have right now is I have two types: episode and  
> > story. Episodes are parents to stories.
> 
> > I want to run a query on stories, filtered or queried based on content  
> > on the Episode.
> 
> > For instance:
> 
> > Episode -  
> > Date: 01/01/2011  
> > Newscaster: Bob Jones
> 
> > Story (child of episode) -  
> > Segment number: 1
> 
> > I want to write a query that will return all stories who have a parent  
> > episode that has the Newscaster "Bob Jones". Is there any way to do  
> > this? My alternate option if I cannot is to store some Episode  
> > content in the Story index so I can get the results I want, but  
> > ideally I would like to keep them in their own types and query them  
> > via that parent/child relationship.
> 
> > I know "has\_child" finds a parent's children that match a specific  
> > query, but I wanted to see if there was a way to build this  
> > "has\_parent" type of functionality that would find all children whose  
> > parents match a specific query.
> 
> > Any idea if this is currently possible?
> 
> > Thanks,  
> > Jim

---

<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, 3:49am UTC](https://discuss.elastic.co/t/is-there-any-way-to-emulate-a-has-parent-type-of-functionality/5803/4 "2017-07-06T03:49:34Z")

</div>


