Skip to content

Commit 4971ab1

Browse files
committed
Fixup aggs test (#69476)
One of the tests that I added in #68871 worked about 99.7% of the time but on some seeds failed to generate the right buckets because on those seeds we would collect each segment with its own aggregator and get bad counts. This "bad counts" problem is known in the terms aggregator - its the price we pay for distributed work. But we can work around it either by forcing all the docs into a single segment or by collecting all of the buckets on the shard. We want to test the code path where don't collect all buckets on the shard so we opt for the former. Closes #69413
1 parent 24677a4 commit 4971ab1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,27 @@ public void testStringShardMinDocCount() throws IOException {
287287
}
288288
}
289289

290-
public void testManyUniqueTerms() throws Exception {
290+
public void testManyTerms() throws Exception {
291291
MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("string", randomBoolean(), true, null);
292292
TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name")
293293
.executionHint(randomFrom(TermsAggregatorFactory.ExecutionMode.values()).toString())
294294
.field("string");
295295
testCase(aggregationBuilder, new MatchAllDocsQuery(), iw -> {
296+
/*
297+
* index all of the fields into a single segment so our
298+
* test gets accurate counts. We *could* set the shard size
299+
* very very high but we want to test the branch of the
300+
* aggregation building code that picks the top sorted aggs.
301+
*/
302+
List<List<? extends IndexableField>> docs = new ArrayList<>();
296303
for (int i = 0; i < TermsAggregatorFactory.MAX_ORDS_TO_TRY_FILTERS - 200; i++) {
297304
String s = String.format(Locale.ROOT, "b%03d", i);
298-
iw.addDocument(doc(fieldType, s));
305+
docs.add(doc(fieldType, s));
299306
if (i % 100 == 7) {
300-
iw.addDocument(doc(fieldType, s));
307+
docs.add(doc(fieldType, s));
301308
}
302309
}
310+
iw.addDocuments(docs);
303311
}, (StringTerms result) -> {
304312
assertThat(
305313
result.getBuckets().stream().map(StringTerms.Bucket::getKey).collect(toList()),

0 commit comments

Comments
 (0)