Search After is returning documents previously seen in earlier page

I am having very similar issue as the following post: Search After API - index state and updated documents

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

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).

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