# How can I retrieve matching children only?

**URL:** <https://discuss.elastic.co/t/how-can-i-retrieve-matching-children-only/5388>\
**Category:** Elasticsearch\
**Created:** [September 15, 2011, 12:24pm UTC](https://discuss.elastic.co/t/how-can-i-retrieve-matching-children-only/5388 "2011-09-15T12:24:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)\
**Post date:** [September 15, 2011, 12:24pm UTC](https://discuss.elastic.co/t/how-can-i-retrieve-matching-children-only/5388/1 "2011-09-15T12:24:59Z")

</div>

Consider a very simple model where we have locations and each location can  
have zero or more events. A location would have properties such as name,  
description and geo point data (lon/lat). An event should be attached to one  
location (its parent) and should have a name and description.

{  
"location" : {  
"properties": {  
"name": { "type": "string", "boost": 2.0, "analyzer": "snowball"  
},  
"description": { "type": "string", "analyzer": "snowball" },  
"geo": { "type": "geo\_point" },  
"exhibits": {  
"type": "nested",  
"properties": {  
"name": { "type": "string", "boost": 2.0, "analyzer":  
"snowball" },  
"description": { "type": "string", "analyzer":  
"snowball" }  
}  
}  
}  
}  
}

What I want to be able to do, is to query for the child documents (events)  
performing a full text search on their names and descriptions. I would like  
to get the matching events back and be able to also get their parent  
location's name. I would also like to narrow down the result set by  
location's coordinates. I _don't_ want to get any events that do not match  
the query. Is that possible in Elastic Search? What types of queries should  
I use?

I have tried putting events as an array property under location (see above)  
and using the nested query but it does not return the kind of results I want  
(I think it returns the whole location, including all events, even the ones  
that do not match my query). I have tried putting events into a separate  
index (mapping?) providing the \_parent property and then performing the  
top\_children query on locations, but I don't get any results.

{  
"exhibit": {  
"\_parent": { "type": "locations" },  
"properties": {  
"name": { "type": "string", "boost": 2.0, "analyzer": "snowball"  
},  
"description": { "type": "string", "analyzer": "snowball" }  
}  
}  
}

Could anyone shed some light? I don't know where to begin...

---

<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:54am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-matching-children-only/5388/2 "2017-07-06T03:54:21Z")

</div>

Closed on July 6, 2017, 3:54am UTC


