# Select documents by a property of the most recent subdocument

**URL:** <https://discuss.elastic.co/t/select-documents-by-a-property-of-the-most-recent-subdocument/91993>\
**Category:** Elasticsearch\
**Created:** [July 5, 2017, 11:10pm UTC](https://discuss.elastic.co/t/select-documents-by-a-property-of-the-most-recent-subdocument/91993 "2017-07-05T23:10:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IsaacInstrumental](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/isaacinstrumental/32/19807_2.png) [@IsaacInstrumental](https://discuss.elastic.co/u/IsaacInstrumental)\
**Post date:** [July 5, 2017, 11:10pm UTC](https://discuss.elastic.co/t/select-documents-by-a-property-of-the-most-recent-subdocument/91993/1 "2017-07-05T23:10:03Z")

</div>

I'm working in a decoupled app, responsible for making calls to an ElasticSearch backend whose schema I don't control. The hits I get back (which are analogous to forum posts) look like this:

```
{
    title: string,
    author: string,
    comments: [
        {
            date: Date,
            author: string,
            body: string,
        },
        ...
    ],
}

```

I want to get back all posts whose most recent comment was written by a specific author. I have searched quite a bit and have not been able to come up with a way to do this with an ElasticSearch query. Could someone enlighten me? Thanks!

---

<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:** [August 2, 2017, 11:10pm UTC](https://discuss.elastic.co/t/select-documents-by-a-property-of-the-most-recent-subdocument/91993/2 "2017-08-02T23:10:14Z")

</div>

Closed on August 2, 2017, 11:10pm UTC

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