Skip to content

Commit

Permalink
Consider total number of aggregations not number of non-empty aggrega…
Browse files Browse the repository at this point in the history
…tions (#107536)

Test are failing because we are computing incorrectly the doc count error for terms aggregation. 
The only difference with the previous versions is that we are considering the number of empty aggregations
instead of the total number of aggregations when computing this value. Making this
change it makes the test happy.
  • Loading branch information
iverase authored Apr 16, 2024
1 parent c2df24b commit ecacb2e
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public final AggregatorReducer termsAggregationReducer(AggregationReduceContext
private class TermsAggregationReducer implements AggregatorReducer {
private final List<List<B>> bucketsList;
private final AggregationReduceContext reduceContext;
private final int size;

private long sumDocCountError = 0;
private final long[] otherDocCount = new long[] { 0 };
Expand All @@ -236,6 +237,7 @@ private class TermsAggregationReducer implements AggregatorReducer {
private TermsAggregationReducer(AggregationReduceContext reduceContext, int size) {
bucketsList = new ArrayList<>(size);
this.reduceContext = reduceContext;
this.size = size;
}

@Override
Expand Down Expand Up @@ -326,7 +328,7 @@ public InternalAggregation get() {
if (sumDocCountError == -1) {
docCountError = -1;
} else {
docCountError = bucketsList.size() == 1 ? 0 : sumDocCountError;
docCountError = size == 1 ? 0 : sumDocCountError;
}
return create(name, result, reduceContext.isFinalReduce() ? getOrder() : thisReduceOrder, docCountError, otherDocCount[0]);
}
Expand Down

0 comments on commit ecacb2e

Please sign in to comment.