# Backward pagination with search\_after when sorting value is null

**URL:** <https://discuss.elastic.co/t/backward-pagination-with-search-after-when-sorting-value-is-null/310799>\
**Category:** Elasticsearch\
**Created:** [July 27, 2022, 8:48pm UTC](https://discuss.elastic.co/t/backward-pagination-with-search-after-when-sorting-value-is-null/310799 "2022-07-27T20:48:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_L](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m_l/32/99690_2.png) [@M\_L](https://discuss.elastic.co/u/M_L)\
**Post date:** [July 27, 2022, 8:48pm UTC](https://discuss.elastic.co/t/backward-pagination-with-search-after-when-sorting-value-is-null/310799/1 "2022-07-27T20:48:01Z")

</div>

Hello,

I have an application which has a dashboard, basically a table with hundreds of thousands of records.

This table has up to 50 different columns. These columns have different types in mapping: keyword, text, boolean, integer.

As records in the table might have the same values, I use sorting as an array of 2 attributes:

1. First attribute is what client wants to sort by. It can be a simple sorting object or some sort query with nested filter.
2. Second attribute is basically a default sorting by id, needed for sorting the documents which have identical values for the column customer wants to sort by.

I checked multiple topics/issues on github and here on elastic forum to understand how to implement search\_after mechanism for back sorting but it's not working for all the cases I need.

Please have a look at the image:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/0/702d67b8b4eeae7bfdeb497e45303317cb03f026.png)

Imagine there is a limit = 3, the customer right now is on the 3d page of a table and all the data is sorted by `name asc, _id asc`

The names are: A, B, C, D, E on the image.  
The ids are numeric parts of the Doc word.

When customer wants to go back to the previous page, which is a page #2 on my picture, what I do is pass the following to elastic:

```auto
sort: [
    {
      name: 'desc'
    },
    {
        _id: 'desc'
    }
],
search_after: [null, Doc7._id]

```

As as result, I get only one document, which is `Doc6: null` on my image. It seems to be logical, because I ask elastic to search by desc after null and id 7 and I have only 1 doc corresponding this..it's `Doc6` but it's not what I need.

I can't make up the solution to get the data that I need.

Could anyone help, please?

---

<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:** [August 24, 2022, 8:48pm UTC](https://discuss.elastic.co/t/backward-pagination-with-search-after-when-sorting-value-is-null/310799/2 "2022-08-24T20:48:04Z")

</div>

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