# Has\_parent query and routing

**URL:** <https://discuss.elastic.co/t/has-parent-query-and-routing/10409>\
**Category:** Elasticsearch\
**Created:** [January 18, 2013, 3:25pm UTC](https://discuss.elastic.co/t/has-parent-query-and-routing/10409 "2013-01-18T15:25:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [January 18, 2013, 3:25pm UTC](https://discuss.elastic.co/t/has-parent-query-and-routing/10409/1 "2013-01-18T15:25:48Z")

</div>

Hi there,

I read in the docs:  
When indexing a child document, the routing value is automatically set to  
be the same as it’s parent, unless the routing value is explicitly  
specified using the routing parameter.  
I was wondering about this routing, the fact that elasticsearch chooses the  
same routing value as it's parent must mean this will improve performance  
query time (why else would it choose the routing value for you).

What would change in the performance characteristics for a has\_parent (or  
has\_child) query if you would change the default and have it so that the  
parents route to let's say shard 0 and childs (of which there are far more)  
to shard 1-7?

Jaap

--

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [January 18, 2013, 3:28pm UTC](https://discuss.elastic.co/t/has-parent-query-and-routing/10409/2 "2013-01-18T15:28:23Z")

</div>

Hello!

ElasticSearch parent child functionality needs to have parent and its children in the same shard, so you just can't place children in other shards.

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

Hi there,

I read in the docs:

When indexing a child document, the routing value is automatically set to be the same as it’s parent, unless the routing value is explicitly specified using the routing parameter.

I was wondering about this routing, the fact that elasticsearch chooses the same routing value as it's parent must mean this will improve performance query time (why else would it choose the routing value for you).

What would change in the performance characteristics for a has\_parent (or has\_child) query if you would change the default and have it so that the parents route to let's say shard 0 and childs (of which there are far more) to shard 1-7?

Jaap

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [January 18, 2013, 4:07pm UTC](https://discuss.elastic.co/t/has-parent-query-and-routing/10409/3 "2013-01-18T16:07:26Z")

</div>

If there was an impl that allowed child docs and parent docs to be on  
different shards the performance would be very slow. (Imagine what sort of  
information would needed to be send over the wire to all nodes to check  
what child belongs what parent doc.)

On top of the fact that parent and its child docs reside on the same shard,  
there is also on id\_cache available to efficiently join the child and  
parent docs to make the joining snappy.

Martijn

On 18 January 2013 16:28, Rafał Kuć [r.kuc@solr.pl](mailto:r.kuc@solr.pl) wrote:

> Hello!
> 
> Elasticsearch parent child functionality needs to have parent and its  
> children in the same shard, so you just can't place children in other  
> shards.
> 
> \*--  
> Regards,  
> Rafał Kuć  
> Sematext :: _[http://sematext.com/](http://sematext.com/)_ :: Solr - Lucene - Nutch -  
> Elasticsearch
> 
> - 
> 
> Hi there,
> 
> I read in the docs:  
> When indexing a child document, the routing value is automatically set to  
> be the same as it’s parent, unless the routing value is explicitly  
> specified using the routing parameter.  
> I was wondering about this routing, the fact that elasticsearch chooses  
> the same routing value as it's parent must mean this will improve  
> performance query time (why else would it choose the routing value for you).
> 
> What would change in the performance characteristics for a has\_parent (or  
> has\_child) query if you would change the default and have it so that the  
> parents route to let's say shard 0 and childs (of which there are far more)  
> to shard 1-7?
> 
> ## Jaap
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<div class="post-metadata">

**Author:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [January 19, 2013, 2:24pm UTC](https://discuss.elastic.co/t/has-parent-query-and-routing/10409/4 "2013-01-19T14:24:49Z")

</div>

That's a clear answer, thanks Rafal and Martijn!

Jaap

--

---

<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, 2:55am UTC](https://discuss.elastic.co/t/has-parent-query-and-routing/10409/5 "2017-07-06T02:55:34Z")

</div>


