# Search parents by latest child

**URL:** <https://discuss.elastic.co/t/search-parents-by-latest-child/22668>\
**Category:** Elasticsearch\
**Created:** [March 14, 2015, 9:31am UTC](https://discuss.elastic.co/t/search-parents-by-latest-child/22668 "2015-03-14T09:31:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [March 14, 2015, 9:31am UTC](https://discuss.elastic.co/t/search-parents-by-latest-child/22668/1 "2015-03-14T09:31:29Z")

</div>

Here's the gist of my data  
scheme: [https://gist.github.com/rauanmaemirov/7b3af9106ccc2963d2a5](https://gist.github.com/rauanmaemirov/7b3af9106ccc2963d2a5)

There are a collection of entities as parents and a collection of events as  
child documents.  
What I need to do is search documents by _the latest event of a particular  
type._

If you run that script on localhost (test index), you could see that search  
request returns all 4 test entities, even though latest event for doc 2  
doesn't match with the query terms.  
I need a way to filter by the latest events and then apply query terms, is  
it possible?

--  
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/03263058-a180-45f2-8a2b-e13d4c9427a5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/03263058-a180-45f2-8a2b-e13d4c9427a5%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:26am UTC](https://discuss.elastic.co/t/search-parents-by-latest-child/22668/2 "2017-07-06T00:26:46Z")

</div>


