Skip to content

Commit

Permalink
docCountError must be 0 for shard level reduce (#9246) (#9282)
Browse files Browse the repository at this point in the history
(cherry picked from commit db768d1)

Signed-off-by: Jay Deng <jayd0104@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 6171cfc commit 2ee5c38
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ private BucketOrder getReduceOrder(List<InternalAggregation> aggregations) {
return thisReduceOrder != null ? thisReduceOrder : order;
}

private long getDocCountError(InternalTerms<?, ?> terms) {
private long getDocCountError(InternalTerms<?, ?> terms, ReduceContext reduceContext) {
int size = terms.getBuckets().size();
if (size == 0 || size < terms.getShardSize() || isKeyOrder(terms.order)) {
// doc_count_error is always computed at the coordinator based on the buckets returned by the shards. This should be 0 during the
// shard level reduce as no buckets are being pruned at this stage.
if (reduceContext.isSliceLevel() || size == 0 || size < terms.getShardSize() || isKeyOrder(terms.order)) {
return 0;
} else if (InternalOrder.isCountDesc(terms.order)) {
if (terms.getDocCountError() > 0) {
Expand Down Expand Up @@ -419,7 +421,7 @@ public InternalAggregation reduce(List<InternalAggregation> aggregations, Reduce
);
}
otherDocCount += terms.getSumOfOtherDocCounts();
final long thisAggDocCountError = getDocCountError(terms);
final long thisAggDocCountError = getDocCountError(terms, reduceContext);
if (sumDocCountError != -1) {
if (thisAggDocCountError == -1) {
sumDocCountError = -1;
Expand Down

0 comments on commit 2ee5c38

Please sign in to comment.