Search parents by latest child

Here's the gist of my data

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

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
To view this discussion on the web visit
For more options, visit