Skip to content

Commit

Permalink
docCountError must be 0 for shard level reduce (opensearch-project#9246)
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Deng <[email protected]>
  • Loading branch information
jed326 authored Aug 12, 2023
1 parent 0b2c07a commit db768d1
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,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 @@ -412,7 +414,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 db768d1

Please sign in to comment.