# First and last record in one query

**URL:** <https://discuss.elastic.co/t/first-and-last-record-in-one-query/6896>\
**Category:** Elasticsearch\
**Created:** [March 5, 2012, 8:32pm UTC](https://discuss.elastic.co/t/first-and-last-record-in-one-query/6896 "2012-03-05T20:32:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SANDPATH7](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SANDPATH7](https://discuss.elastic.co/u/SANDPATH7)\
**Post date:** [March 5, 2012, 8:32pm UTC](https://discuss.elastic.co/t/first-and-last-record-in-one-query/6896/1 "2012-03-05T20:32:15Z")

</div>

Hi Guys,

Is it possible for me to get the first and the last record in one query? There is a crude way to set pagination to 1,1 and then total,total to get the first and last record but by doing this, i have to query 3 times.  
First to get total records, second to get first and third one to get the last record.

Can i get first and last record in one shot.

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:** [July 6, 2017, 3:37am UTC](https://discuss.elastic.co/t/first-and-last-record-in-one-query/6896/2 "2017-07-06T03:37:16Z")

</div>

Closed on July 6, 2017, 3:37am UTC


