# Search After Pagination with sort field in Query

**URL:** <https://discuss.elastic.co/t/search-after-pagination-with-sort-field-in-query/283952>\
**Category:** Elasticsearch\
**Created:** [September 11, 2021, 4:52pm UTC](https://discuss.elastic.co/t/search-after-pagination-with-sort-field-in-query/283952 "2021-09-11T16:52:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulpatwari](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@rahulpatwari](https://discuss.elastic.co/u/rahulpatwari)\
**Post date:** [September 11, 2021, 4:52pm UTC](https://discuss.elastic.co/t/search-after-pagination-with-sort-field-in-query/283952/1 "2021-09-11T16:52:35Z")

</div>

Hi,

I am using search after pagination logic for deep pagination.  
The search query extracts documents with a specific DateTime range.

```auto
                  {
                    "range": {
                      "my_date_time": {
                        "gte": "2021-08-10T15:05:00.000Z",
                        "lt": "2021-08-10T15:10:00.000Z"
                      }
                    }
                  }

```

_my\_date\_time_ field which is used to identify DateTime in the query is being used as the sorting field with ASC order.

For the search after logic to work, the last document's DateTime should be used with _search\_after_ in the next query.

Would there be any performance benefit if the last document's DateTime is used in _gte_ of range query i.e. modifying the range query for every next page with the last document's DateTime value of current page.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 13, 2021, 2:40pm UTC](https://discuss.elastic.co/t/search-after-pagination-with-sort-field-in-query/283952/2 "2021-09-13T14:40:42Z")

</div>

Your solution will return different documents to what the search after pagination will do - so I am unsure what you asking? Maybe you can clarify?

---

<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:** [October 11, 2021, 2:41pm UTC](https://discuss.elastic.co/t/search-after-pagination-with-sort-field-in-query/283952/3 "2021-10-11T14:41:07Z")

</div>

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