# Grandchild is not getting fetched by parent id

**URL:** <https://discuss.elastic.co/t/grandchild-is-not-getting-fetched-by-parent-id/21657>\
**Category:** Elasticsearch\
**Created:** [January 15, 2015, 11:44am UTC](https://discuss.elastic.co/t/grandchild-is-not-getting-fetched-by-parent-id/21657 "2015-01-15T11:44:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iv\_Igi](https://avatars.discourse-cdn.com/v4/letter/i/c5a1d2/32.png) [@Iv\_Igi](https://discuss.elastic.co/u/Iv_Igi)\
**Post date:** [January 15, 2015, 11:44am UTC](https://discuss.elastic.co/t/grandchild-is-not-getting-fetched-by-parent-id/21657/1 "2015-01-15T11:44:39Z")

</div>

I am experiencing an issue while trying to retrieve a grandchild record by  
its parent ID. (child-grandchild relationship)  
The amount of hits in result is always zero.  
Also the same request is working fine for parent-child relationship.

My records are getting organized kinda like this:

Account --(one to one)--\> User --(one to one)--\> Address

My execution environment is:

- Fedora 21 CE
- openjdk 1.8.0\_25
- ES 1.4.2

Here is a script that is showing the problem

# index creation

curl -XPUT "localhost:9200/the\_index/" -d "{  
"mappings": {  
"account" : {},  
"user" : {  
"\_parent" : {  
"type" : "account"  
}  
},  
"address" : {  
"\_parent" : {  
"type" : "user"  
}  
}  
}  
}";

# mrsmith account creation

curl -XPUT "localhost:9200/the\_index/account/mrsmith" -d "{  
"foo" : "foo"  
}";

# john user creation

curl -XPUT "localhost:9200/the\_index/user/john?parent=mrsmith" -d "{  
"bar" : "bar"  
}";

# john user creation

curl -XPUT "localhost:9200/the\_index/address/smithshouse?parent=john" -d "{  
"baz" : "baz"  
}";

# Here I am trying to retrieve a record. Getting zero hits.

curl -XGET "localhost:9200/the\_index/address/\_search?pretty" -d "{  
"query" : { "bool" : { "must" : { "term" : { "\_parent" :  
"john" } } } }  
}";

# Another approach with has\_parent query type. Still getting zero hits.

curl -XGET "localhost:9200/the\_index/address/\_search?pretty" -d "{  
"query" : {  
"has\_parent" : {  
"parent\_type" : "user",  
"query" : {  
"term" : {  
"\_id" : "john"  
}  
}  
}  
}  
}";

# OK, lets try a routed search. Nope

curl -XGET "localhost:9200/the\_index/address/\_search?routing=john&pretty"  
-d "{  
"query" : { "bool" : { "must" : { "term" : { "\_parent" :  
"john" } } } }  
}";

# Routed has\_parent query. Same

curl -XGET "localhost:9200/the\_index/address/\_search?routing=john&pretty"  
-d "{  
"query" : {  
"has\_parent" : {  
"parent\_type" : "user",  
"query" : {  
"term" : {  
"\_id" : "john"  
}  
}  
}  
}  
}";

# Retrieving a record by itself. Going just fine.

curl -XGET "localhost:9200/the\_index/address/smithshouse?parent=john";

# Querying for user record with the same query. Got a hit.

curl -XGET "localhost:9200/the\_index/user/\_search?pretty" -d "{  
"query" : { "bool" : { "must" : { "term" : { "\_parent" :  
"mrsmith" } } } }  
}";

The output:

{"acknowledged":true}  
{"\_index":"the\_index","\_type":"account","\_id":"mrsmith","\_version":1,"created":true}{"\_index":"the\_index","\_type":"user","\_id":"john","\_version":1,"created":true}{"\_index":"the\_index","\_type":"address","\_id":"smithshouse","\_version":1,"created":true}  
{  
"took" : 54,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}  
{  
"took" : 221,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}  
{  
"took" : 35,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}  
{  
"took" : 481,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}  
{"\_index":"the\_index","\_type":"address","\_id":"smithshouse","\_version":1,"found":true,"\_source":{  
"baz" : "baz"  
}}  
{  
"took" : 65,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "the\_index",  
"\_type" : "user",  
"\_id" : "john",  
"\_score" : 1.0,  
"\_source":{  
"bar" : "bar"  
}  
} ]  
}  
}

You can find out on resuls that ES got the required shard, but no records  
have been fetched.  
Probably I am doing it in a wrong way, and if it so please fix me up.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![masaru](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@masaru](https://discuss.elastic.co/u/masaru)\
**Post date:** [January 16, 2015, 4:04am UTC](https://discuss.elastic.co/t/grandchild-is-not-getting-fetched-by-parent-id/21657/2 "2015-01-16T04:04:03Z")

</div>

Hi Iv,

You’d need to specify both parent and routing when you index grand children.  
See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/grandparents.html)

Masaru

On January 15, 2015 at 20:44:43, Iv Igi ([sayoneas@gmail.com](mailto:sayoneas@gmail.com)) wrote:

> I am experiencing an issue while trying to retrieve a grandchild record by  
> its parent ID. (child-grandchild relationship)  
> The amount of hits in result is always zero.  
> Also the same request is working fine for parent-child relationship.
> 
> My records are getting organized kinda like this:
> 
> Account --(one to one)--\> User --(one to one)--\> Address
> 
> My execution environment is:
> 
> - Fedora 21 CE
> - openjdk 1.8.0\_25
> - ES 1.4.2
> 
> Here is a script that is showing the problem
> 
> # index creation
> 
> curl -XPUT "localhost:9200/the\_index/" -d "{  
> "mappings": {  
> "account" : {},  
> "user" : {  
> "\_parent" : {  
> "type" : "account"  
> }  
> },  
> "address" : {  
> "\_parent" : {  
> "type" : "user"  
> }  
> }  
> }  
> }";
> 
> # mrsmith account creation
> 
> curl -XPUT "localhost:9200/the\_index/account/mrsmith" -d "{  
> "foo" : "foo"  
> }";
> 
> # john user creation
> 
> curl -XPUT "localhost:9200/the\_index/user/john?parent=mrsmith" -d "{  
> "bar" : "bar"  
> }";
> 
> # john user creation
> 
> curl -XPUT "localhost:9200/the\_index/address/smithshouse?parent=john" -d "{  
> "baz" : "baz"  
> }";
> 
> # Here I am trying to retrieve a record. Getting zero hits.
> 
> curl -XGET "localhost:9200/the\_index/address/\_search?pretty" -d "{  
> "query" : { "bool" : { "must" : { "term" : { "\_parent" :  
> "john" } } } }  
> }";
> 
> # Another approach with has\_parent query type. Still getting zero hits.
> 
> curl -XGET "localhost:9200/the\_index/address/\_search?pretty" -d "{  
> "query" : {  
> "has\_parent" : {  
> "parent\_type" : "user",  
> "query" : {  
> "term" : {  
> "\_id" : "john"  
> }  
> }  
> }  
> }  
> }";
> 
> # OK, lets try a routed search. Nope
> 
> curl -XGET "localhost:9200/the\_index/address/\_search?routing=john&pretty"  
> -d "{  
> "query" : { "bool" : { "must" : { "term" : { "\_parent" :  
> "john" } } } }  
> }";
> 
> # Routed has\_parent query. Same
> 
> curl -XGET "localhost:9200/the\_index/address/\_search?routing=john&pretty"  
> -d "{  
> "query" : {  
> "has\_parent" : {  
> "parent\_type" : "user",  
> "query" : {  
> "term" : {  
> "\_id" : "john"  
> }  
> }  
> }  
> }  
> }";
> 
> # Retrieving a record by itself. Going just fine.
> 
> curl -XGET "localhost:9200/the\_index/address/smithshouse?parent=john";
> 
> # Querying for user record with the same query. Got a hit.
> 
> curl -XGET "localhost:9200/the\_index/user/\_search?pretty" -d "{  
> "query" : { "bool" : { "must" : { "term" : { "\_parent" :  
> "mrsmith" } } } }  
> }";
> 
> The output:
> 
> {"acknowledged":true}  
> {"\_index":"the\_index","\_type":"account","\_id":"mrsmith","\_version":1,"created":true}{"\_index":"the\_index","\_type":"user","\_id":"john","\_version":1,"created":true}{"\_index":"the\_index","\_type":"address","\_id":"smithshouse","\_version":1,"created":true}  
> {  
> "took" : 54,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }  
> {  
> "took" : 221,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }  
> {  
> "took" : 35,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }  
> {  
> "took" : 481,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }  
> {"\_index":"the\_index","\_type":"address","\_id":"smithshouse","\_version":1,"found":true,"\_source":{  
> "baz" : "baz"  
> }}  
> {  
> "took" : 65,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "the\_index",  
> "\_type" : "user",  
> "\_id" : "john",  
> "\_score" : 1.0,  
> "\_source":{  
> "bar" : "bar"  
> }  
> } ]  
> }  
> }
> 
> You can find out on resuls that ES got the required shard, but no records  
> have been fetched.  
> Probably I am doing it in a wrong way, and if it so please fix me up.
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch"  
> group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.54b88def.46e87ccd.1877%40citra.local](https://groups.google.com/d/msgid/elasticsearch/etPan.54b88def.46e87ccd.1877%40citra.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Iv\_Igi](https://avatars.discourse-cdn.com/v4/letter/i/c5a1d2/32.png) [@Iv\_Igi](https://discuss.elastic.co/u/Iv_Igi)\
**Post date:** [January 16, 2015, 10:34pm UTC](https://discuss.elastic.co/t/grandchild-is-not-getting-fetched-by-parent-id/21657/3 "2015-01-16T22:34:30Z")

</div>

Got my mistake, thank you!  
And sorry for missing the man page.

пятница, 16 января 2015 г., 7:05:17 UTC+3 пользователь Masaru Hasegawa  
написал:

> Hi Iv,
> 
> You’d need to specify both parent and routing when you index grand  
> children.  
> See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/grandparents.html)
> 
> Masaru
> 
> On January 15, 2015 at 20:44:43, Iv Igi ([sayo...@gmail.com](mailto:sayo...@gmail.com) \<javascript:\>)  
> wrote:
> 
> > I am experiencing an issue while trying to retrieve a grandchild record  
> > by  
> > its parent ID. (child-grandchild relationship)  
> > The amount of hits in result is always zero.  
> > Also the same request is working fine for parent-child relationship.
> > 
> > My records are getting organized kinda like this:
> > 
> > Account --(one to one)--\> User --(one to one)--\> Address
> > 
> > My execution environment is:
> > 
> > - Fedora 21 CE
> > - openjdk 1.8.0\_25
> > - ES 1.4.2
> > 
> > Here is a script that is showing the problem
> > 
> > # index creation
> > 
> > curl -XPUT "localhost:9200/the\_index/" -d "{  
> > "mappings": {  
> > "account" : {},  
> > "user" : {  
> > "\_parent" : {  
> > "type" : "account"  
> > }  
> > },  
> > "address" : {  
> > "\_parent" : {  
> > "type" : "user"  
> > }  
> > }  
> > }  
> > }";
> > 
> > # mrsmith account creation
> > 
> > curl -XPUT "localhost:9200/the\_index/account/mrsmith" -d "{  
> > "foo" : "foo"  
> > }";
> > 
> > # john user creation
> > 
> > curl -XPUT "localhost:9200/the\_index/user/john?parent=mrsmith" -d "{  
> > "bar" : "bar"  
> > }";
> > 
> > # john user creation
> > 
> > curl -XPUT "localhost:9200/the\_index/address/smithshouse?parent=john" -d  
> > "{  
> > "baz" : "baz"  
> > }";
> > 
> > # Here I am trying to retrieve a record. Getting zero hits.
> > 
> > curl -XGET "localhost:9200/the\_index/address/\_search?pretty" -d "{  
> > "query" : { "bool" : { "must" : { "term" : { "\_parent" :  
> > "john" } } } }  
> > }";
> > 
> > # Another approach with has\_parent query type. Still getting zero hits.
> > 
> > curl -XGET "localhost:9200/the\_index/address/\_search?pretty" -d "{  
> > "query" : {  
> > "has\_parent" : {  
> > "parent\_type" : "user",  
> > "query" : {  
> > "term" : {  
> > "\_id" : "john"  
> > }  
> > }  
> > }  
> > }  
> > }";
> > 
> > # OK, lets try a routed search. Nope
> > 
> > curl -XGET  
> > "localhost:9200/the\_index/address/\_search?routing=john&pretty"  
> > -d "{  
> > "query" : { "bool" : { "must" : { "term" : { "\_parent" :  
> > "john" } } } }  
> > }";
> > 
> > # Routed has\_parent query. Same
> > 
> > curl -XGET  
> > "localhost:9200/the\_index/address/\_search?routing=john&pretty"  
> > -d "{  
> > "query" : {  
> > "has\_parent" : {  
> > "parent\_type" : "user",  
> > "query" : {  
> > "term" : {  
> > "\_id" : "john"  
> > }  
> > }  
> > }  
> > }  
> > }";
> > 
> > # Retrieving a record by itself. Going just fine.
> > 
> > curl -XGET "localhost:9200/the\_index/address/smithshouse?parent=john";
> > 
> > # Querying for user record with the same query. Got a hit.
> > 
> > curl -XGET "localhost:9200/the\_index/user/\_search?pretty" -d "{  
> > "query" : { "bool" : { "must" : { "term" : { "\_parent" :  
> > "mrsmith" } } } }  
> > }";
> > 
> > The output:
> > 
> > {"acknowledged":true}
> 
> {"\_index":"the\_index","\_type":"account","\_id":"mrsmith","\_version":1,"created":true}{"\_index":"the\_index","\_type":"user","\_id":"john","\_version":1,"created":true}{"\_index":"the\_index","\_type":"address","\_id":"smithshouse","\_version":1,"created":true}
> 
> > {  
> > "took" : 54,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }  
> > {  
> > "took" : 221,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }  
> > {  
> > "took" : 35,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }  
> > {  
> > "took" : 481,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> 
> {"\_index":"the\_index","\_type":"address","\_id":"smithshouse","\_version":1,"found":true,"\_source":{
> 
> > "baz" : "baz"  
> > }}  
> > {  
> > "took" : 65,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 1,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "the\_index",  
> > "\_type" : "user",  
> > "\_id" : "john",  
> > "\_score" : 1.0,  
> > "\_source":{  
> > "bar" : "bar"  
> > }  
> > } ]  
> > }  
> > }
> > 
> > You can find out on resuls that ES got the required shard, but no  
> > records  
> > have been fetched.  
> > Probably I am doing it in a wrong way, and if it so please fix me up.
> > 
> > --  
> > You received this message because you are subscribed to the Google  
> > Groups "elasticsearch"  
> > group.  
> > To unsubscribe from this group and stop receiving emails from it, send  
> > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com).
> 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c5764ca1-a4cd-419a-873a-9a8dc2985d10%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c5764ca1-a4cd-419a-873a-9a8dc2985d10%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:38am UTC](https://discuss.elastic.co/t/grandchild-is-not-getting-fetched-by-parent-id/21657/4 "2017-07-06T00:38:16Z")

</div>


