# Search After is returning documents previously seen in earlier page

**URL:** https://discuss.elastic.co/t/search-after-is-returning-documents-previously-seen-in-earlier-page/186899
**Category:** Elasticsearch
**Created:** [June 21, 2019, 2:42pm UTC](https://discuss.elastic.co/t/search-after-is-returning-documents-previously-seen-in-earlier-page/186899 "2019-06-21T14:42:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jim\_Ford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_ford/32/48542_2.png) [@Jim\_Ford](https://discuss.elastic.co/u/Jim_Ford)
#### Post date: [June 21, 2019, 2:42pm UTC](https://discuss.elastic.co/t/search-after-is-returning-documents-previously-seen-in-earlier-page/186899/1 "2019-06-21T14:42:30Z")

</div>

I am having very similar issue as the following post: [Search After API - index state and updated documents](https://discuss.elastic.co/t/search-after-api-index-state-and-updated-documents/90792)

given the following initial query:

> ```
> {
> "size": 3,
> "query": {
> "query_string": {
> "query": "apple"
> }
> },
> "sort": [
> {
> "_score": "desc"
> },
> {
> "date": "desc"
> },
> {
> "_uid": "desc"
> }
> ]
> }
> 
> ```

I am retrieving later pages using search after like so (with values from the last record returned by the first query):

> ```
> {
> "size": 3,
> "query": {
> "query_string": {
> "query": "apple"
> }
> },
> "sort": [
> {
> "_score": "desc"
> },
> {
> "date": "desc"
> },
> {
> "_uid": "desc"
> }
> ],
> "search_after": [
> 1.4757546,
> 1557340985983,
> "document#d422926b21ead5d99fa5814246fbd20978a6df2a"
> ]
> }
> 
> ```

After a few pages I start to see the same document with different scores coming up on other pages.

Given the same query should the same document have different scores on different pages?

How can I avoid duplicate hits (I mean identical document) while using search after for pagination?

Please Help!

Thanks,  
Jim

---

<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: [June 22, 2019, 7:24am UTC](https://discuss.elastic.co/t/search-after-is-returning-documents-previously-seen-in-earlier-page/186899/2 "2019-06-22T07:24:01Z")

</div>

you could try to set the preference (for example using the session id of the user executing the reuqest) and thus make sure you are hitting the same shards and see if that problem goes away.

My assumption is that across shards the scores are potentially different and thus hitting different copies of shard results in different result ordering.

Out of curiosity: What is your use-case for search after and using score as the first sort option - I have rarely seen it (despite a couple of cases come to mind).

---

<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 20, 2019, 7:24am UTC](https://discuss.elastic.co/t/search-after-is-returning-documents-previously-seen-in-earlier-page/186899/3 "2019-07-20T07:24:03Z")

</div>

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