Skip to content

Commit 21edf4d

Browse files
authored
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 1a8f227 commit 21edf4d

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
@@ -286,19 +286,27 @@ public void testStringShardMinDocCount() throws IOException {
286286
}
287287
}
288288

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

0 commit comments

Comments
 (0)