Skip to content

Virtual Sort field for automatic tie-breaking #56828

Closed
@jimczi

Description

@jimczi

The pagination of search requests using search_after require to use a tiebreaker that is unique per document. This is done automatically on sorted _scroll queries by tie-breaking documents on the index/shardId/docID tuple. This tuple is not accessible to normal search requests so the other option is to copy the _id of the document into a doc value field and use it as a tiebreaker.
This solution is difficult to implement for solutions that are not in charge of indexation.
With the introduction of the search context for requests, we'll be able to paginate over a set of sorted results using search_after with the guarantee to see the same documents during the walk. Since the internal document id wouldn't change between requests, using the tuple that _scroll queries use become possible.
This issue proposes to expose a virtual sort field called _tiebreak (or any name that suits better). The field would be accessible as a sort criteria that can be used with a search context to ensure consistent ordering. The field would be composed of:

  • The index UUID
  • The shard ID
  • The internal document ID

The order of the composition should be discussed but the main goal is to allow consistent ordering using search_after without relying on manual operations at index-time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search/SearchSearch-related issues that do not fall into other categories>enhancementTeam:SearchMeta label for search team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions