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

Improve reduction of terms aggregations #61779

Merged
merged 17 commits into from
Sep 4, 2020

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Sep 1, 2020

Today, the terms aggregation reduces multiple aggregations at once using a map
to group same buckets together. This operation can be costly since it requires
to lookup every bucket in a global map with no particular order.
This commit changes how term buckets are sorted by shards and partial reduces in
order to be able to reduce results using a merge-sort strategy.
For bwc, results are merged with the legacy code if any of the aggregations use
a different sort (if the shard response was created by a node in prior versions).

Relates #51857

Today, the terms aggregation reduces multiple aggregations at once using a map
to group same buckets together. This operation can be costly since it requires
to lookup every bucket in a global map with no particular order.
This commit changes how term buckets are sorted by shards and partial reduces in
order to be able to reduce results using a merge-sort strategy.
For bwc, results are merged with the legacy code if any of the aggregations use
a different sort (if it was returned by a node in prior versions).

Relates elastic#51857
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Sep 1, 2020
@@ -189,44 +220,173 @@ protected final void doWriteTo(StreamOutput out) throws IOException {
@Override
public abstract B getBucketByKey(String term);

@Override
private static class IteratorAndCurrent<B extends InternalTerms.Bucket<B>> {
Copy link
Member

Choose a reason for hiding this comment

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

Fine for now, but I feel like we have four or five of these and maybe it'd be worth merging their implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1, I pushed d752ac7

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM

@jimczi
Copy link
Contributor Author

jimczi commented Sep 2, 2020

@elasticmachine run elasticsearch-ci/packaging-sample-windows

@jimczi
Copy link
Contributor Author

jimczi commented Sep 4, 2020

@elasticmachine run elasticsearch-ci/packaging-sample-windows

1 similar comment
@jimczi
Copy link
Contributor Author

jimczi commented Sep 4, 2020

@elasticmachine run elasticsearch-ci/packaging-sample-windows

@jimczi jimczi merged commit 49ae2bb into elastic:master Sep 4, 2020
@jimczi jimczi deleted the terms_aggs_merge_reduce branch September 4, 2020 13:08
jimczi added a commit to jimczi/elasticsearch that referenced this pull request Sep 7, 2020
This commit adapts the bwc version checks added in elastic#61779 and disable
bwc tests until the backport elastic#62028 is merged.
jimczi added a commit that referenced this pull request Sep 7, 2020
This commit adapts the bwc version checks added in #61779 and disable
bwc tests until the backport #62028 is merged.
jimczi added a commit that referenced this pull request Sep 7, 2020
Today, the terms aggregation reduces multiple aggregations at once using a map
to group same buckets together. This operation can be costly since it requires
to lookup every bucket in a global map with no particular order.
This commit changes how term buckets are sorted by shards and partial reduces in
order to be able to reduce results using a merge-sort strategy.
For bwc, results are merged with the legacy code if any of the aggregations use
a different sort (if it was returned by a node in prior versions).

Relates #51857
jimczi added a commit to jimczi/elasticsearch that referenced this pull request Sep 7, 2020
jimczi added a commit that referenced this pull request Sep 7, 2020
jimczi added a commit to jimczi/elasticsearch that referenced this pull request Nov 2, 2020
This change fixes a bug introduced in elastic#61779 that uses a compound order to
compare buckets when merging. The bug is triggered when the compound order
uses a primary sort ordered by key (asc or desc).
This commit ensures that we always extract the primary sort when comparing keys
during merging.
The PR is marked as no-issue since the bug has not been released in any official version.
jimczi added a commit that referenced this pull request Nov 5, 2020
This change fixes a bug introduced in #61779 that uses a compound order to
compare buckets when merging. The bug is triggered when the compound order
uses a primary sort ordered by key (asc or desc).
This commit ensures that we always extract the primary sort when comparing keys
during merging.
The PR is marked as no-issue since the bug has not been released in any official version.
jimczi added a commit that referenced this pull request Nov 5, 2020
This change fixes a bug introduced in #61779 that uses a compound order to
compare buckets when merging. The bug is triggered when the compound order
uses a primary sort ordered by key (asc or desc).
This commit ensures that we always extract the primary sort when comparing keys
during merging.
The PR is marked as no-issue since the bug has not been released in any official version.
jimczi added a commit that referenced this pull request Nov 5, 2020
This change fixes a bug introduced in #61779 that uses a compound order to
compare buckets when merging. The bug is triggered when the compound order
uses a primary sort ordered by key (asc or desc).
This commit ensures that we always extract the primary sort when comparing keys
during merging.
The PR is marked as no-issue since the bug has not been released in any official version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Aggregations Aggregations >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants