Skip to content

Commit 9443de3

Browse files
committed
Fix docCountError calculation for multiple reduces
Fix docCountError calculation in case of multiple reduces. It fixes 2 mistakes in elastic#43874. The first error was introduced in the original PR, where unknown doc count errors were initialized equal to 0, the second was introduced during in order to fix the first one by ignoring these 0s, which essentially disabled the original fix. Fixes elastic#75667
1 parent dfcb341 commit 9443de3

File tree

8 files changed

+8
-9
lines changed

8 files changed

+8
-9
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/search/aggregations/TermsReduceBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private StringTerms newTerms(Random rand, BytesRef[] dict, boolean withNested) {
154154
true,
155155
0,
156156
buckets,
157-
0L
157+
null
158158
);
159159
}
160160

benchmarks/src/main/java/org/elasticsearch/benchmark/search/aggregations/bucket/terms/StringTermsSerializationBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private StringTerms newTerms(boolean withNested) {
7070
false,
7171
100000,
7272
resultBuckets,
73-
0L
73+
null
7474
);
7575
}
7676

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ public void testFixedDocs() throws Exception {
10341034
* Tests the upper bounds are correct when performing incremental reductions
10351035
* See https://github.com/elastic/elasticsearch/issues/40005 for more details
10361036
*/
1037-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/75667")
10381037
public void testIncrementalReduction() {
10391038
SearchResponse response = client().prepareSearch("idx_fixed_docs_3", "idx_fixed_docs_4", "idx_fixed_docs_5")
10401039
.addAggregation(terms("terms")

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/AbstractInternalTerms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private long getDocCountError(A terms) {
133133
if (size == 0 || size < terms.getShardSize() || isKeyOrder(terms.getOrder())) {
134134
return 0;
135135
} else if (InternalOrder.isCountDesc(terms.getOrder())) {
136-
if (terms.getDocCountError() != null && terms.getDocCountError() > 0) {
136+
if (terms.getDocCountError() != null) {
137137
// If there is an existing docCountError for this agg then
138138
// use this as the error for this aggregation
139139
return terms.getDocCountError();

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ StringTerms buildResult(long owningBucketOrd, long otherDocCount, StringTerms.Bu
765765
}
766766
return new StringTerms(name, reduceOrder, order, bucketCountThresholds.getRequiredSize(),
767767
bucketCountThresholds.getMinDocCount(), metadata(), format, bucketCountThresholds.getShardSize(), showTermDocCountError,
768-
otherDocCount, Arrays.asList(topBuckets), 0L);
768+
otherDocCount, Arrays.asList(topBuckets), null);
769769
}
770770

771771
@Override

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/MapStringTermsAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ StringTerms buildResult(long owningBucketOrd, long otherDocCount, StringTerms.Bu
446446
}
447447
return new StringTerms(name, reduceOrder, order, bucketCountThresholds.getRequiredSize(),
448448
bucketCountThresholds.getMinDocCount(), metadata(), format, bucketCountThresholds.getShardSize(), showTermDocCountError,
449-
otherDocCount, Arrays.asList(topBuckets), 0L);
449+
otherDocCount, Arrays.asList(topBuckets), null);
450450
}
451451

452452
@Override

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ LongTerms buildResult(long owningBucketOrd, long otherDocCount, LongTerms.Bucket
372372
showTermDocCountError,
373373
otherDocCount,
374374
List.of(topBuckets),
375-
0L
375+
null
376376
);
377377
}
378378

@@ -454,7 +454,7 @@ DoubleTerms buildResult(long owningBucketOrd, long otherDocCount, DoubleTerms.Bu
454454
showTermDocCountError,
455455
otherDocCount,
456456
List.of(topBuckets),
457-
0L
457+
null
458458
);
459459
}
460460

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTermsAggregatorFromFilters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ protected boolean lessThan(OrdBucket a, OrdBucket b) {
227227
showTermDocCountError,
228228
otherDocsCount,
229229
buckets,
230-
0L
230+
null
231231
);
232232
}
233233

0 commit comments

Comments
 (0)