|
102 | 102 | import java.io.IOException;
|
103 | 103 | import java.net.InetAddress;
|
104 | 104 | import java.util.ArrayList;
|
| 105 | +import java.util.Arrays; |
105 | 106 | import java.util.Collections;
|
106 | 107 | import java.util.Comparator;
|
107 | 108 | import java.util.HashMap;
|
@@ -258,6 +259,33 @@ public void testSimple() throws Exception {
|
258 | 259 | }, fieldType);
|
259 | 260 | }
|
260 | 261 |
|
| 262 | + public void testStringShardMinDocCount() throws IOException { |
| 263 | + MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("string", true, true, null); |
| 264 | + for (TermsAggregatorFactory.ExecutionMode executionMode : TermsAggregatorFactory.ExecutionMode.values()) { |
| 265 | + TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name") |
| 266 | + .field("string") |
| 267 | + .executionHint(executionMode.toString()) |
| 268 | + .size(2) |
| 269 | + .minDocCount(2) |
| 270 | + .shardMinDocCount(2) |
| 271 | + .order(BucketOrder.key(true)); |
| 272 | + testCase(aggregationBuilder, new MatchAllDocsQuery(), iw -> { |
| 273 | + // force single shard/segment |
| 274 | + iw.addDocuments(Arrays.asList( |
| 275 | + doc(fieldType, "a", "b"), |
| 276 | + doc(fieldType, "", "c", "d"), |
| 277 | + doc(fieldType, "b", "d"), |
| 278 | + doc(fieldType, "b"))); |
| 279 | + }, (InternalTerms<?, ?> result) -> { |
| 280 | + assertEquals(2, result.getBuckets().size()); |
| 281 | + assertEquals("b", result.getBuckets().get(0).getKeyAsString()); |
| 282 | + assertEquals(3L, result.getBuckets().get(0).getDocCount()); |
| 283 | + assertEquals("d", result.getBuckets().get(1).getKeyAsString()); |
| 284 | + assertEquals(2L, result.getBuckets().get(1).getDocCount()); |
| 285 | + }, fieldType); |
| 286 | + } |
| 287 | + } |
| 288 | + |
261 | 289 | public void testManyUniqueTerms() throws Exception {
|
262 | 290 | MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("string", randomBoolean(), true, null);
|
263 | 291 | TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name")
|
|
0 commit comments