# Possible to return matched children in a query with has\_child?

**URL:** <https://discuss.elastic.co/t/possible-to-return-matched-children-in-a-query-with-has-child/12310>\
**Category:** Elasticsearch\
**Created:** [June 7, 2013, 3:52am UTC](https://discuss.elastic.co/t/possible-to-return-matched-children-in-a-query-with-has-child/12310 "2013-06-07T03:52:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![F21](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@F21](https://discuss.elastic.co/u/F21)\
**Post date:** [June 7, 2013, 3:52am UTC](https://discuss.elastic.co/t/possible-to-return-matched-children-in-a-query-with-has-child/12310/1 "2013-06-07T03:52:48Z")

</div>

I have 2 types, people and pet.

Each pet has a parent which is a people.

I am running a search to search on the people and pet names and to return  
the people for matched people and pets.

This is the query I am using and it works great:  
{  
"query":{  
"bool":{  
"must":[  
{  
"term":{  
"statuses":{  
"value":"active",  
"boost":1  
}  
}  
}  
],  
"should":[  
{  
"match":{  
"people.name":{  
"type":"phrase\_prefix",  
"query":"john"  
}  
}  
},  
{  
"has\_child":{  
"query":{  
"prefix":{  
"pet.name":{  
"value":"john",  
"boost":1  
}  
}  
},  
"type":"pet"  
}  
}  
]  
}  
}  
}

The problem is that if the match is a pet's name, I would like to also  
return the pet that matched along with the results. Is there any way to do  
this?

Currently, I am running the same query again, but only against pets, which  
is grossly inefficient.

Cheers 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:32am UTC](https://discuss.elastic.co/t/possible-to-return-matched-children-in-a-query-with-has-child/12310/2 "2017-07-06T02:32:28Z")

</div>


