# Three-level parent/child-mapping: Query the second level via its childs

**URL:** https://discuss.elastic.co/t/three-level-parent-child-mapping-query-the-second-level-via-its-childs/7184
**Category:** Elasticsearch
**Created:** [March 30, 2012, 6:12pm UTC](https://discuss.elastic.co/t/three-level-parent-child-mapping-query-the-second-level-via-its-childs/7184 "2012-03-30T18:12:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Felix\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_s/32/2933_2.png) [@Felix\_S](https://discuss.elastic.co/u/Felix_S)
#### Post date: [March 30, 2012, 6:12pm UTC](https://discuss.elastic.co/t/three-level-parent-child-mapping-query-the-second-level-via-its-childs/7184/1 "2012-03-30T18:12:45Z")

</div>

Hi!

I'm trying to build an index schema with three levels, lets call them a, b  
and c, which are joined via parent-child-relations. The 'a' type is parent  
of the 'b' type, which again is parent of the 'c' type. Querying the top  
level, the 'a' type, via its 'b' children works without issues. However,  
when I try to query the middle 'b' level via its 'c' children, i.e. query  
/myindex/b/ with a has\_child() query for type 'c' with some query that  
matches one of the 'c' documents in my index, I always get zero results. I  
tested this against 0.19.1 and the latest version from git, both via the  
Java API and via curl'ed json requests. I'm attaching a shell script with  
my curl requests, I hope I didnt overlook any errors in there, but I  
quadruple checked it and couldn't find any.

Regards,  
Felix

---

<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: [April 3, 2012, 1:41pm UTC](https://discuss.elastic.co/t/three-level-parent-child-mapping-query-the-second-level-via-its-childs/7184/2 "2012-04-03T13:41:04Z")

</div>

When you index mult level mappings, for the third level you need to make  
sure to set teh routing value to the top most doc id, otherwise, it will be  
routed wrongly. For example, index c with routing of a1. See if it helps...

On Fri, Mar 30, 2012 at 9:12 PM, Felix S. [f.sappelt@clueda.com](mailto:f.sappelt@clueda.com) wrote:

> Hi!
> 
> I'm trying to build an index schema with three levels, lets call them a, b  
> and c, which are joined via parent-child-relations. The 'a' type is parent  
> of the 'b' type, which again is parent of the 'c' type. Querying the top  
> level, the 'a' type, via its 'b' children works without issues. However,  
> when I try to query the middle 'b' level via its 'c' children, i.e. query  
> /myindex/b/ with a has\_child() query for type 'c' with some query that  
> matches one of the 'c' documents in my index, I always get zero results. I  
> tested this against 0.19.1 and the latest version from git, both via the  
> Java API and via curl'ed json requests. I'm attaching a shell script with  
> my curl requests, I hope I didnt overlook any errors in there, but I  
> quadruple checked it and couldn't find any.
> 
> Regards,  
> Felix

---

<div class="post-metadata">

### Author: ![Felix\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_s/32/2933_2.png) [@Felix\_S](https://discuss.elastic.co/u/Felix_S)
#### Post date: [April 4, 2012, 1:06pm UTC](https://discuss.elastic.co/t/three-level-parent-child-mapping-query-the-second-level-via-its-childs/7184/3 "2012-04-04T13:06:14Z")

</div>

Yes, that works. Thanks!

Am Dienstag, 3. April 2012 15:41:04 UTC+2 schrieb kimchy:

> When you index mult level mappings, for the third level you need to make  
> sure to set teh routing value to the top most doc id, otherwise, it will be  
> routed wrongly. For example, index c with routing of a1. See if it helps...
> 
> On Fri, Mar 30, 2012 at 9:12 PM, Felix S. [f.sappelt@clueda.com](mailto:f.sappelt@clueda.com) wrote:
> 
> > Hi!
> > 
> > I'm trying to build an index schema with three levels, lets call them a,  
> > b and c, which are joined via parent-child-relations. The 'a' type is  
> > parent of the 'b' type, which again is parent of the 'c' type. Querying the  
> > top level, the 'a' type, via its 'b' children works without issues.  
> > However, when I try to query the middle 'b' level via its 'c' children,  
> > i.e. query /myindex/b/ with a has\_child() query for type 'c' with some  
> > query that matches one of the 'c' documents in my index, I always get zero  
> > results. I tested this against 0.19.1 and the latest version from git, both  
> > via the Java API and via curl'ed json requests. I'm attaching a shell  
> > script with my curl requests, I hope I didnt overlook any errors in there,  
> > but I quadruple checked it and couldn't find any.
> > 
> > Regards,  
> > Felix

---

<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:33am UTC](https://discuss.elastic.co/t/three-level-parent-child-mapping-query-the-second-level-via-its-childs/7184/4 "2017-07-06T03:33:42Z")

</div>


