# Using search\_after. Getting skipped count and rest count

**URL:** https://discuss.elastic.co/t/using-search-after-getting-skipped-count-and-rest-count/197186
**Category:** Elasticsearch
**Created:** [August 28, 2019, 6:40pm UTC](https://discuss.elastic.co/t/using-search-after-getting-skipped-count-and-rest-count/197186 "2019-08-28T18:40:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![einfoman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/einfoman/32/9186_2.png) [@einfoman](https://discuss.elastic.co/u/einfoman)
#### Post date: [August 28, 2019, 6:40pm UTC](https://discuss.elastic.co/t/using-search-after-getting-skipped-count-and-rest-count/197186/1 "2019-08-28T18:40:27Z")

</div>

Hi, everyone!

I have an index of documents which search using sorting and `search_after` parameter. Every page is an outer request. I need to know, how many documents is skipped for the current value of `search_after` parameter and how many document is rest to the end.

Which way I could do this?

---

<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: [August 29, 2019, 7:49am UTC](https://discuss.elastic.co/t/using-search-after-getting-skipped-count-and-rest-count/197186/2 "2019-08-29T07:49:33Z")

</div>

I do not see a way of doing this currently. Also, it does not make sense to keep track of this in the client, as those numbers can change due to concurrent indexing/deletions.

May I ask what the use-case is? Maybe there is another way of achieving what you need.

---

<div class="post-metadata">

### Author: ![einfoman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/einfoman/32/9186_2.png) [@einfoman](https://discuss.elastic.co/u/einfoman)
#### Post date: [August 29, 2019, 9:19am UTC](https://discuss.elastic.co/t/using-search-after-getting-skipped-count-and-rest-count/197186/3 "2019-08-29T09:19:44Z")

</div>

I'll try to explain. There are two scenarios.

## The first scenario

I have a paged list of documents sorted by date (for our purposes). Actually this is web page. This page contains:

- total documents count (might approximately, for example, 250 or 1000+)
- current page number
- next page link (if there are documents)
- prev page link (if page is not first or, equivalently, skipped count large than 0)  
The next/prev links contain encoded `after_search` parameter. For the next link (call it as `afterKey`) is a `sort`-set of the last document of list. For the prev link (call it as `beforeKey`) is a `sort`-set of the first document of list.  
Here we need to know current page number, that is `skipped` count. Yes, count of documents can change but it is OK.

## The second scenario

I have API. It has a method for filtering of documents. It also support `cursor` (actually, `search_after`). But it returns count of documents in the light of `search_after` but not total count. This behaviour cannot be change.

---

<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: [September 26, 2019, 9:19am UTC](https://discuss.elastic.co/t/using-search-after-getting-skipped-count-and-rest-count/197186/4 "2019-09-26T09:19:49Z")

</div>

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