# Trouble with grand-parent/parent/child relationship

**URL:** <https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132>\
**Category:** Elasticsearch\
**Created:** [August 7, 2017, 3:39pm UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132 "2017-08-07T15:39:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://discuss.elastic.co/u/chrisburrell)\
**Post date:** [August 7, 2017, 3:39pm UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132/1 "2017-08-07T15:39:27Z")

</div>

Hi

I'm trying to do something, which I thought was pretty simple. A User can have multiple accounts and an account have multiple messages. For some reason, I can see the parents for accounts but I can't see a parent for the message.

Here are the curl messages that I'm running. Is there something I'm doing that's obviously wrong?

curl -XDELETE 'localhost:9200/myindex'  
curl -v -XPUT 'localhost:9200/myindex' -H 'Content-Type: application/json' -d'  
{  
"mappings": {  
"user": {},  
"account": {  
"\_parent": {  
"type": "user"  
}  
},  
"message": {  
"\_parent": {  
"type": "account"  
}  
}

}  
}'

curl -XPUT 'localhost:9200/myindex/user/1?pretty&refresh' -H 'Content-Type: application/json' -d'  
{  
name: "Chris Burrell"  
}  
'

curl -XPUT 'localhost:9200/myindex/account/2?pretty&parent=1&refresh' -H 'Content-Type: application/json' -d'  
{  
"accountType": "classic",  
"paymentReference": "C1",  
"userId": "chris"  
}  
'

curl -XPUT 'localhost:9200/myindex/account/3?pretty&parent=1&refresh' -H 'Content-Type: application/json' -d'  
{  
"accountType": "isa",  
"paymentReference": "I1",  
"userId": "chris"  
}  
'

curl -XPUT 'localhost:9200/myindex/message/4?pretty&parent=2&refresh' -H 'Content-Type: application/json' -d'  
{  
"id" : "chrispir1",  
"awaitingFunds": 1000,  
"totalRequested": 1200,  
"accountId": "chrisclassic"  
}  
'

curl -XPOST localhost:9200/myindex/message/\_search?pretty -d'  
{  
"query": {  
"has\_parent": {  
"parent\_type": "account",  
"query": {  
"match\_all": {}  
}  
}  
}  
}'

I'm a bit confused - as I had thought this use case was supported?  
Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 7, 2017, 4:58pm UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132/2 "2017-08-07T16:58:48Z")

</div>

Can you elaborate a bit more on what you get vs. what you expect?

---

<div class="post-metadata">

**Author:** ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://discuss.elastic.co/u/chrisburrell)\
**Post date:** [August 8, 2017, 8:34am UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132/3 "2017-08-08T08:34:35Z")

</div>

Hi @jpountz

Sorry - I thought I copied the response in. That was a poor post of mine. The response I get is that there are no children of 'account'. I had assumes that after the curl -XPUT ‘localhost:9200/myindex/message/4?pretty&parent=2&refresh’, seen as '2' is the account, then the search below would return a message.

Does that make sense? If I do a similar search for parent-type 'user' for myindex/account, then I do get an account, but the same does not seem to be true for the account/message parent/child relationship.

Request:

> ```
> curl -XPOST localhost:9200/myindex/message/_search?pretty -d’
> {
> "query": {
> "has_parent": {
> "parent_type": "account",
> "query": {
> "match_all": {}
> }
> }
> }
> }'
> 
> ```

Response:

> {  
> "took" : 5,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }

---

<div class="post-metadata">

**Author:** ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://discuss.elastic.co/u/chrisburrell)\
**Post date:** [August 10, 2017, 9:22am UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132/4 "2017-08-10T09:22:27Z")

</div>

Anyone? Does that make sense? Could that be a bug (I'm assuming not, with something so basic!)  
Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://discuss.elastic.co/u/chrisburrell)\
**Post date:** [August 18, 2017, 6:14am UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132/5 "2017-08-18T06:14:01Z")

</div>

Hi all

I don't want to believe that such functionality is broken. That would be really odd and surprising, however, my use case is so simple, I would appreciate if someone could take a brief look.

- Create parent mapping between A -\> B, and mapping between B -\> C
- Create child to parent, and grand child to child
- Elasticsearch fails to return any results for parent\_type of B.

Perhaps that's because it doesn't know how to route the query without going down the tree of A?  
Thanks  
Chris

---

<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:** [September 15, 2017, 6:14am UTC](https://discuss.elastic.co/t/trouble-with-grand-parent-parent-child-relationship/96132/6 "2017-09-15T06:14:16Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
