# Parent indexes with multiple children

**URL:** https://discuss.elastic.co/t/parent-indexes-with-multiple-children/3826
**Category:** Elasticsearch
**Created:** [January 25, 2011, 2:06pm UTC](https://discuss.elastic.co/t/parent-indexes-with-multiple-children/3826 "2011-01-25T14:06:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![frazer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frazer/32/2752_2.png) [@frazer](https://discuss.elastic.co/u/frazer)
#### Post date: [January 25, 2011, 2:06pm UTC](https://discuss.elastic.co/t/parent-indexes-with-multiple-children/3826/1 "2011-01-25T14:06:59Z")

</div>

I have a couple of questions regarding parent child mappings and multi  
children searching.

1. I know the following structure/mapping works for parent child:  
[http://localhost:9200/blogs/blog](http://localhost:9200/blogs/blog)  
[http://localhost:9200/blogs/blog\_comments](http://localhost:9200/blogs/blog_comments)  
[http://localhost:9200/blogs/blog\_tags](http://localhost:9200/blogs/blog_tags)

The above was based on this gist ([https://gist.github.com/758398](https://gist.github.com/758398))

However the client I am using generates the indexes in the following  
manner  
[http://localhost:9200/blogs/blog](http://localhost:9200/blogs/blog)  
[http://localhost:9200/blog\_comments/blog\_comment](http://localhost:9200/blog_comments/blog_comment)  
[http://localhost:9200/blog\_tags/blog\_tag](http://localhost:9200/blog_tags/blog_tag)

I know the child needs to be in the same shard as the parent (or is  
recommended). I just wanted to know is there any way to route the  
indexes in the second example(maybe in the mapping) to create the  
parent child relationships?

1. Does a parent index support searching on multiple children, would  
something like this work and would this be the most efficient way to  
search across multiple children?

curl -XGET '[http://localhost:9200/blogs/\_search](http://localhost:9200/blogs/_search)' -d '{  
"query" : {  
"filtered" : {  
"query" : {"term" : {"blog\_site\_id" : "1"} },  
"filter" : {  
"or" : [  
{  
"has\_child" : {  
"type" : "comment",  
"query" :{"term" : {"body" : "some text"} }  
}  
},{  
"has\_child" : {  
"type" : "tags",  
"query" :{"term" : {"tag\_name" : "some text"} }  
}  
}]  
}  
}  
}  
}'

1. Anyone know if there are plans to support returning the child docs  
and/or a has\_parent query option?

Thanks

Frazer

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [January 25, 2011, 6:13pm UTC](https://discuss.elastic.co/t/parent-indexes-with-multiple-children/3826/2 "2011-01-25T18:13:02Z")

</div>

On Tuesday, January 25, 2011 at 4:06 PM, frazer wrote:

> I have a couple of questions regarding parent child mappings and multi  
> children searching.
> 
> 1. I know the following structure/mapping works for parent child:  
> [http://localhost:9200/blogs/blog](http://localhost:9200/blogs/blog)  
> [http://localhost:9200/blogs/blog\_comments](http://localhost:9200/blogs/blog_comments)  
> [http://localhost:9200/blogs/blog\_tags](http://localhost:9200/blogs/blog_tags)
> 
> The above was based on this gist ([gist:758398 · GitHub](https://gist.github.com/758398))
> 
> However the client I am using generates the indexes in the following  
> manner  
> [http://localhost:9200/blogs/blog](http://localhost:9200/blogs/blog)  
> [http://localhost:9200/blog\_comments/blog\_comment](http://localhost:9200/blog_comments/blog_comment)  
> [http://localhost:9200/blog\_tags/blog\_tag](http://localhost:9200/blog_tags/blog_tag)
> 
> I know the child needs to be in the same shard as the parent (or is  
> recommended).

Its not recommended, its a requirement. You can't actually do parent child relationship without it being the case.

> I just wanted to know is there any way to route the  
> indexes in the second example(maybe in the mapping) to create the  
> parent child relationships?

No, it only works when the parent and the child are within the same shard.

> 1. Does a parent index support searching on multiple children, would  
> something like this work and would this be the most efficient way to  
> search across multiple children?

Yep, this should work.

> curl -XGET '[http://localhost:9200/blogs/\_search](http://localhost:9200/blogs/_search)' -d '{  
> "query" : {  
> "filtered" : {  
> "query" : {"term" : {"blog\_site\_id" : "1"} },  
> "filter" : {  
> "or" : [  
> {  
> "has\_child" : {  
> "type" : "comment",  
> "query" :{"term" : {"body" : "some text"} }  
> }  
> },{  
> "has\_child" : {  
> "type" : "tags",  
> "query" :{"term" : {"tag\_name" : "some text"} }  
> }  
> }]  
> }  
> }  
> }  
> }'
> 
> 1. Anyone know if there are plans to support returning the child docs  
> and/or a has\_parent query option?
> 
> Thanks
> 
> Frazer

---

<div class="post-metadata">

### Author: ![frazer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frazer/32/2752_2.png) [@frazer](https://discuss.elastic.co/u/frazer)
#### Post date: [January 25, 2011, 7:04pm UTC](https://discuss.elastic.co/t/parent-indexes-with-multiple-children/3826/3 "2011-01-25T19:04:18Z")

</div>

Thanks Shay

On Jan 25, 1:13 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> On Tuesday, January 25, 2011 at 4:06 PM, frazer wrote:
> 
> > I have a couple of questions regarding parent child mappings and multi  
> > children searching.
> 
> > 1. I know the following structure/mapping works for parent child:  
> > [http://localhost:9200/blogs/blog](http://localhost:9200/blogs/blog)  
> > [http://localhost:9200/blogs/blog\_comments](http://localhost:9200/blogs/blog_comments)  
> > [http://localhost:9200/blogs/blog\_tags](http://localhost:9200/blogs/blog_tags)
> 
> > The above was based on this gist ([gist:758398 · GitHub](https://gist.github.com/758398))
> 
> > However the client I am using generates the indexes in the following  
> > manner  
> > [http://localhost:9200/blogs/blog](http://localhost:9200/blogs/blog)  
> > [http://localhost:9200/blog\_comments/blog\_comment](http://localhost:9200/blog_comments/blog_comment)  
> > [http://localhost:9200/blog\_tags/blog\_tag](http://localhost:9200/blog_tags/blog_tag)
> 
> > I know the child needs to be in the same shard as the parent (or is  
> > recommended).
> 
> Its not recommended, its a requirement. You can't actually do parent child relationship without it being the case.
> 
> > I just wanted to know is there any way to route the  
> > indexes in the second example(maybe in the mapping) to create the  
> > parent child relationships?
> 
> No, it only works when the parent and the child are within the same shard.
> 
> > 1. Does a parent index support searching on multiple children, would  
> > something like this work and would this be the most efficient way to  
> > search across multiple children?
> 
> Yep, this should work.
> 
> > curl -XGET '[http://localhost:9200/blogs/\_search'-d](http://localhost:9200/blogs/_search'-d) '{  
> > "query" : {  
> > "filtered" : {  
> > "query" : {"term" : {"blog\_site\_id" : "1"} },  
> > "filter" : {  
> > "or" : [  
> > {  
> > "has\_child" : {  
> > "type" : "comment",  
> > "query" :{"term" : {"body" : "some text"} }  
> > }  
> > },{  
> > "has\_child" : {  
> > "type" : "tags",  
> > "query" :{"term" : {"tag\_name" : "some text"} }  
> > }  
> > }]  
> > }  
> > }  
> > }  
> > }'
> 
> > 1. Anyone know if there are plans to support returning the child docs  
> > and/or a has\_parent query option?
> 
> > Thanks
> 
> > Frazer

---

<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, 4:13am UTC](https://discuss.elastic.co/t/parent-indexes-with-multiple-children/3826/4 "2017-07-06T04:13:16Z")

</div>


