Skip to content

Commit 7482625

Browse files
committed
Move
1 parent 91283ed commit 7482625

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ private static TermsAggregatorSupplier bytesSupplier() {
109109
ExecutionMode execution = null;
110110
if (executionHint != null) {
111111
execution = ExecutionMode.fromString(executionHint);
112+
} else {
113+
if (matchNoDocs(context, parent) && bucketCountThresholds.getMinDocCount() > 0) {
114+
execution = ExecutionMode.MAP;
115+
}
112116
}
113117
// In some cases, using ordinals is just not supported: override it
114118
if (valuesSource.hasOrdinals() == false) {
115119
execution = ExecutionMode.MAP;
116120
}
117-
if (matchNoDocs(context, parent) && bucketCountThresholds.getMinDocCount() > 0) {
118-
execution = ExecutionMode.MAP;
119-
}
120121
if (execution == null) {
121122
execution = ExecutionMode.GLOBAL_ORDINALS;
122123
}

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
import static org.elasticsearch.search.aggregations.PipelineAggregatorBuilders.bucketScript;
142142
import static org.elasticsearch.test.MapMatcher.assertMap;
143143
import static org.elasticsearch.test.MapMatcher.matchesMap;
144+
import static org.hamcrest.Matchers.anyOf;
144145
import static org.hamcrest.Matchers.closeTo;
145146
import static org.hamcrest.Matchers.either;
146147
import static org.hamcrest.Matchers.equalTo;
@@ -286,8 +287,18 @@ public void testSimple() throws Exception {
286287
}
287288

288289
public void testMatchNoDocsQuery() throws Exception {
290+
for (TermsAggregatorFactory.ExecutionMode executionMode : TermsAggregatorFactory.ExecutionMode.values()) {
291+
testMatchNoDocsQuery(executionMode);
292+
}
293+
testMatchNoDocsQuery(null);
294+
}
295+
296+
private void testMatchNoDocsQuery(TermsAggregatorFactory.ExecutionMode hint) throws Exception {
289297
MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("string", randomBoolean(), true, Collections.emptyMap());
290298
TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name").field("string");
299+
if (hint != null) {
300+
aggregationBuilder.executionHint(hint.toString());
301+
}
291302
CheckedConsumer<RandomIndexWriter, IOException> createIndex = iw -> {
292303
iw.addDocument(doc(fieldType, "a", "b"));
293304
iw.addDocument(doc(fieldType, "", "c", "a"));
@@ -298,12 +309,8 @@ public void testMatchNoDocsQuery() throws Exception {
298309
createIndex,
299310
(InternalTerms<?, ?> result) -> { assertEquals(0, result.getBuckets().size()); },
300311
new AggTestConfig(aggregationBuilder, fieldType).withQuery(new MatchNoDocsQuery())
301-
.withCheckAggregator(checkTopLevelAggregatorNoRewrites(TermsAggregatorFactory.ExecutionMode.MAP))
312+
.withCheckAggregator(checkTopLevelAggregator(hint == null ? TermsAggregatorFactory.ExecutionMode.MAP : hint))
302313
);
303-
304-
debugTestCase(aggregationBuilder, new MatchNoDocsQuery(), createIndex, (result, impl, debug) -> {
305-
assertEquals(impl, MapStringTermsAggregator.class);
306-
}, fieldType);
307314
}
308315

309316
public void testStringShardMinDocCount() throws IOException {
@@ -362,7 +369,7 @@ public void testStringShardZeroMinDocCount() throws IOException {
362369
assertEquals(0L, result.getBuckets().get(1).getDocCount());
363370
},
364371
new AggTestConfig(aggregationBuilder, fieldType).withQuery(new TermQuery(new Term("string", "e")))
365-
.withCheckAggregator(checkTopLevelAggregatorNoRewrites(executionMode))
372+
.withCheckAggregator(checkTopLevelAggregator(executionMode))
366373
);
367374
}
368375

@@ -389,7 +396,7 @@ public void testStringShardZeroMinDocCount() throws IOException {
389396
assertEquals(0L, result.getBuckets().get(1).getDocCount());
390397
},
391398
new AggTestConfig(aggregationBuilder, fieldType).withQuery(new TermQuery(new Term("string", "e")))
392-
.withCheckAggregator(checkTopLevelAggregatorNoRewrites(executionMode))
399+
.withCheckAggregator(checkTopLevelAggregator(executionMode))
393400
);
394401
}
395402
}
@@ -432,7 +439,7 @@ public void testStringZeroMinDocCountMatchNone() throws IOException {
432439
assertEquals(0L, result.getBuckets().get(1).getDocCount());
433440
},
434441
new AggTestConfig(aggregationBuilder, fieldType).withQuery(new MatchNoDocsQuery())
435-
.withCheckAggregator(checkTopLevelAggregatorNoRewrites(executionMode))
442+
.withCheckAggregator(checkTopLevelAggregator(executionMode))
436443
);
437444
}
438445

@@ -459,7 +466,7 @@ public void testStringZeroMinDocCountMatchNone() throws IOException {
459466
assertEquals(0L, result.getBuckets().get(1).getDocCount());
460467
},
461468
new AggTestConfig(aggregationBuilder, fieldType).withQuery(new MatchNoDocsQuery())
462-
.withCheckAggregator(checkTopLevelAggregatorNoRewrites(executionMode))
469+
.withCheckAggregator(checkTopLevelAggregator(executionMode))
463470
);
464471
}
465472
}
@@ -2356,10 +2363,13 @@ private String randomHint() {
23562363
return randomFrom(TermsAggregatorFactory.ExecutionMode.values()).toString();
23572364
}
23582365

2359-
private Consumer<Aggregator> checkTopLevelAggregatorNoRewrites(TermsAggregatorFactory.ExecutionMode executionMode) {
2366+
private Consumer<Aggregator> checkTopLevelAggregator(TermsAggregatorFactory.ExecutionMode executionMode) {
23602367
return switch (executionMode) {
23612368
case MAP -> a -> assertThat(a, instanceOf(MapStringTermsAggregator.class));
2362-
case GLOBAL_ORDINALS -> a -> assertThat(a, instanceOf(GlobalOrdinalsStringTermsAggregator.class));
2369+
case GLOBAL_ORDINALS -> a -> assertThat(
2370+
a,
2371+
anyOf(instanceOf(GlobalOrdinalsStringTermsAggregator.class), instanceOf(StringTermsAggregatorFromFilters.class))
2372+
);
23632373
};
23642374
}
23652375
}

0 commit comments

Comments
 (0)