# How to get last N documents with ascending order

**URL:** https://discuss.elastic.co/t/how-to-get-last-n-documents-with-ascending-order/232028
**Category:** Elasticsearch
**Created:** [May 11, 2020, 1:29pm UTC](https://discuss.elastic.co/t/how-to-get-last-n-documents-with-ascending-order/232028 "2020-05-11T13:29:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JavaDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javadeveloper/32/67144_2.png) [@JavaDeveloper](https://discuss.elastic.co/u/JavaDeveloper)
#### Post date: [May 11, 2020, 1:29pm UTC](https://discuss.elastic.co/t/how-to-get-last-n-documents-with-ascending-order/232028/1 "2020-05-11T13:29:21Z")

</div>

Hi everyone.  
I know with the following command, we can get last N documents:

```auto
POST index/_search
{
   "size": N, (N=10 for example)
   "sort": { "timestamp": "desc"},
   "query": {
      "match_all": {}
   }
}

```

But if I use `asc` , it gives me 10 first documents!  
So :  
How can I get **last N document where the results are sorted by ascending not descending.**

---

<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: [June 8, 2020, 1:29pm UTC](https://discuss.elastic.co/t/how-to-get-last-n-documents-with-ascending-order/232028/2 "2020-06-08T13:29:25Z")

</div>

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