Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort field tiebreaker for PIT (point in time) readers #66093

Merged
merged 12 commits into from
Dec 18, 2020

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Dec 9, 2020

This commit introduces a new sort field called _shard_doc that
can be used in conjunction with a PIT to consistently tiebreak
identical sort values. The sort value is a numeric long that is
composed of the ordinal of the shard (assigned by the coordinating node)
and the internal Lucene document ID. These two values are consistent within
a PIT so this sort criteria can be used as the tiebreaker of any search
requests.
Since this sort criteria is stable we'd like to add it automatically to any
sorted search requests that use a PIT but we also need to expose it explicitly
in order to be able to:

  • Reverse the order of the tiebreaking, useful to search "before" search_after.
  • Force the primary sort to use it in order to benefit from the search_after optimization when sorting by index order (to be released in Lucene 8.8.

I plan to add the documentation and the automatic configuration for PIT in a follow up since this change is already big.

Relates #56828

This commit introduces a new sort field called `_shard_doc` that
can be used in conjunction with a PIT to consistently tiebreak
identical sort values. The sort value is a numeric long that is
composed of the ordinal of the shard (assigned by the coordinating node)
and the internal Lucene document ID. These two values are consistent within
a PIT so this sort criteria can be used as the tiebreaker of any search
requests.
Since this sort criteria is stable we'd like to add it automatically to any
sorted search requests that use a PIT but we also need to expose it explicitly
in order to be able to:
* Reverse the order of the tiebreaking, useful to search "before" `search_after`.
* Force the primary sort to use it in order to benefit from the `search_after` optimization when sorting by index order (to be released in Lucene 8.8.

I plan to add the documentation and the automatic configuration for PIT in a follow up since this change is already big.

Relates elastic#56828
@jimczi jimczi added >feature :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.11.0 labels Dec 9, 2020
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Dec 9, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)


@Override
public void setTopValue(Long value) {
int topShardIndex = (int) (value >> 32);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since _shard_doc field is a user-facing now, do we want add checks for its correctness, for example ensure that topShardIndex >=0 and a doc part of the value is also >=0? May be better to do this check in SearchAfterBuilder?

Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimczi Thanks, I left some small comments, but overall LGTM, a really great addition!

@jimczi jimczi added v7.12.0 and removed v7.11.0 labels Dec 16, 2020
@jimczi jimczi merged commit c756ce1 into elastic:master Dec 18, 2020
@jimczi jimczi deleted the shard_doc_sort_field branch December 18, 2020 11:13
jimczi added a commit that referenced this pull request Dec 18, 2020
This commit introduces a new sort field called `_shard_doc` that
can be used in conjunction with a PIT to consistently tiebreak
identical sort values. The sort value is a numeric long that is
composed of the ordinal of the shard (assigned by the coordinating node)
and the internal Lucene document ID. These two values are consistent within
a PIT so this sort criteria can be used as the tiebreaker of any search
requests.
Since this sort criteria is stable we'd like to add it automatically to any
sorted search requests that use a PIT but we also need to expose it explicitly
in order to be able to:
* Reverse the order of the tiebreaking, useful to search "before" `search_after`.
* Force the primary sort to use it in order to benefit from the `search_after` optimization when sorting by index order (to be released in Lucene 8.8.

I plan to add the documentation and the automatic configuration for PIT in a follow up since this change is already big.

Relates #56828
dnhatn added a commit that referenced this pull request Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants