Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run terms concurrently when cardinality is only lower than shard size #110369

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/110369.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 110369
summary: Run terms concurrently when cardinality is only lower than shard size
area: Aggregations
type: bug
issues:
- 105505
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public static boolean supportsParallelCollection(long cardinality, BucketOrder o
return cardinality <= KEY_ORDER_CONCURRENCY_THRESHOLD;
}
BucketCountThresholds adjusted = TermsAggregatorFactory.adjustBucketCountThresholds(bucketCountThresholds, order);
return cardinality <= adjusted.getShardSize();
// for cardinality equal to shard size, we don't know if there were more terms when merging.
return cardinality < adjusted.getShardSize();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public boolean supportsParallelCollection(ToLongFunction<String> fieldCardinalit
{
TermsAggregationBuilder terms = new TermsAggregationBuilder("terms");
terms.shardSize(10);
assertTrue(terms.supportsParallelCollection(field -> randomIntBetween(1, 10)));
assertFalse(terms.supportsParallelCollection(field -> randomIntBetween(11, 100)));
assertTrue(terms.supportsParallelCollection(field -> randomIntBetween(1, 9)));
assertFalse(terms.supportsParallelCollection(field -> randomIntBetween(10, 100)));
}
{
TermsAggregationBuilder terms = new TermsAggregationBuilder("terms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ public void testSupportsParallelCollection() {
List<String> fields = new ArrayList<>();
assertTrue(builder.supportsParallelCollection(field -> {
fields.add(field);
return randomIntBetween(0, 10);
return randomIntBetween(0, 9);
}));
assertEquals(List.of("field1", "field2"), fields);
assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(11, 100)));
assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(10, 100)));
terms.terms(
List.of(
sourceBuilder1.build(),
Expand All @@ -183,14 +183,14 @@ public void testSupportsParallelCollection() {
List.of(sourceBuilder1.build(), sourceBuilder2.build())
);
terms.shardSize(10);
assertTrue(terms.supportsParallelCollection(field -> randomIntBetween(0, 10)));
assertTrue(terms.supportsParallelCollection(field -> randomIntBetween(0, 9)));
terms.subAggregation(new TermsAggregationBuilder("name") {
@Override
public boolean supportsParallelCollection(ToLongFunction<String> fieldCardinalityResolver) {
return false;
}
});
assertFalse(terms.supportsParallelCollection(field -> randomIntBetween(0, 10)));
assertFalse(terms.supportsParallelCollection(field -> randomIntBetween(0, 9)));
}
{
MultiValuesSourceFieldConfig.Builder sourceBuilder1 = new MultiValuesSourceFieldConfig.Builder();
Expand Down