Skip to content

Terms aggs that run as filters ignore shard_min_doc_count #69323

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

Merged
merged 2 commits into from
Feb 22, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ protected boolean lessThan(OrdBucket a, OrdBucket b) {
};
OrdBucket spare = null;
for (InternalFilters.InternalBucket b : filters.getBuckets()) {
if (b.getDocCount() < bucketCountThresholds.getShardMinDocCount()) {
continue;
}
if (spare == null) {
spare = new OrdBucket(showTermDocCountError, format);
} else {
Expand Down Expand Up @@ -194,6 +197,9 @@ protected boolean lessThan(OrdBucket a, OrdBucket b) {
} else {
buckets = new ArrayList<>(filters.getBuckets().size());
for (InternalFilters.InternalBucket b : filters.getBuckets()) {
if (b.getDocCount() < bucketCountThresholds.getShardMinDocCount()) {
continue;
}
buckets.add(buildBucket(b));
}
Collections.sort(buckets, reduceOrder.comparator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -258,6 +259,33 @@ public void testSimple() throws Exception {
}, fieldType);
}

public void testStringShardMinDocCount() throws IOException {
MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("string", true, true, null);
for (TermsAggregatorFactory.ExecutionMode executionMode : TermsAggregatorFactory.ExecutionMode.values()) {
TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name")
.field("string")
.executionHint(executionMode.toString())
.size(2)
.minDocCount(2)
.shardMinDocCount(2)
.order(BucketOrder.key(true));
testCase(aggregationBuilder, new MatchAllDocsQuery(), iw -> {
// force single shard/segment
iw.addDocuments(Arrays.asList(
doc(fieldType, "a", "b"),
doc(fieldType, "", "c", "d"),
doc(fieldType, "b", "d"),
doc(fieldType, "b")));
}, (InternalTerms<?, ?> result) -> {
assertEquals(2, result.getBuckets().size());
assertEquals("b", result.getBuckets().get(0).getKeyAsString());
assertEquals(3L, result.getBuckets().get(0).getDocCount());
assertEquals("d", result.getBuckets().get(1).getKeyAsString());
assertEquals(2L, result.getBuckets().get(1).getDocCount());
}, fieldType);
}
}

public void testManyUniqueTerms() throws Exception {
MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("string", randomBoolean(), true, null);
TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name")
Expand Down