# Elasticsearch query - Most recent log for each user, for field logtype='x'

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-most-recent-log-for-each-user-for-field-logtype-x/263170>\
**Category:** Elasticsearch\
**Created:** [February 3, 2021, 9:24pm UTC](https://discuss.elastic.co/t/elasticsearch-query-most-recent-log-for-each-user-for-field-logtype-x/263170 "2021-02-03T21:24:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brennan](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@brennan](https://discuss.elastic.co/u/brennan)\
**Post date:** [February 3, 2021, 9:24pm UTC](https://discuss.elastic.co/t/elasticsearch-query-most-recent-log-for-each-user-for-field-logtype-x/263170/1 "2021-02-03T21:24:31Z")

</div>

I am trying to query elasticsearch to get the most recent log for all userIDs where we only include one log per user with field logtype='x'

if logtype='x' then get 1 log per userID where the date of this log is the most recent for each userID

How can I create this query?

---

<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:** [March 3, 2021, 9:25pm UTC](https://discuss.elastic.co/t/elasticsearch-query-most-recent-log-for-each-user-for-field-logtype-x/263170/2 "2021-03-03T21:25:14Z")

</div>

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