# How to get last X documents sorted by a timestamp

**URL:** <https://discuss.elastic.co/t/how-to-get-last-x-documents-sorted-by-a-timestamp/191046>\
**Category:** Elasticsearch\
**Created:** [July 17, 2019, 3:35pm UTC](https://discuss.elastic.co/t/how-to-get-last-x-documents-sorted-by-a-timestamp/191046 "2019-07-17T15:35:36Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 17, 2019, 3:45pm UTC](https://discuss.elastic.co/t/how-to-get-last-x-documents-sorted-by-a-timestamp/191046/6 "2019-07-17T15:45:53Z")

</div>

filter by type of event. sort on the time stamp and set size to 1?

But I might be missing the problem.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-get-last-x-documents-sorted-by-a-timestamp/191046)._
