title: Paging in Elasticsearch when results have equal scores
body: <p>Is it possible to implement reliable paging of elasticsearch search results if multiple documents have equal scores?</p>
  
  <p>I'm experimenting with custom scoring in elasticsearch. Many of the scoring expressions I try yield result sets where many documents have equal scores. They seem to come in the same order each time I try, but can it be guaranteed? </p>
  
  <p>AFAIU it can't, especially not if there is more than one shard in a cluster. Documents with equal score wrt. a given elasticsearch query are returned in random, non-deterministic order that can change between invocations of the same query, even if the underlying database does not change (and therefore paging is unreliable) unless one of the following holds:</p>
  
  <ol>
  <li>I use <code>function_score</code> to guarantee that the score is unique for each document (e.g. by using a unique number field).</li>
  <li>I use <code>sort</code> and guarantee that the sorting defines a total order (e.g. by using a unique field as fallback if everything else is equal).</li>
  </ol>
  
  <p>Can anyone confirm (and maybe point at some reference)?</p>
  
  <p>Does this change if I know that there is only one primary shard without any replicas (see other, similar querstion: <a href="https://stackoverflow.com/questions/22867546/inconsistent-ordering-of-results-across-primary-replica-for-documents-with-equi">Inconsistent ordering of results across primary /replica for documents with equivalent score</a>) ? E.g. if I guarantee that there is one shard AND there is no change in the database between two invocations of the same query then that query will return results in the same order?</p>
  
  <p>What are other alternatives (if any)?</p>