diff --git a/docs/reference/search/profile.asciidoc b/docs/reference/search/profile.asciidoc
index 67918710d4728..3dd30deafa771 100644
--- a/docs/reference/search/profile.asciidoc
+++ b/docs/reference/search/profile.asciidoc
@@ -696,7 +696,7 @@ The API returns the following result:
]
},
{
- "name": "MultiBucketCollector: [[my_scoped_agg, my_global_agg]]",
+ "name": "BucketCollectorWrapper: [BucketCollectorWrapper[bucketCollector=[my_scoped_agg, my_global_agg]]]",
"reason": "aggregation",
"time_in_nanos": 867617
}
diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java b/server/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java
index 1fd32eb55cccf..67ef52bd859ea 100644
--- a/server/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java
+++ b/server/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java
@@ -52,8 +52,8 @@ public static void preProcess(SearchContext context) {
context.queryCollectors().put(AggregationPhase.class, BucketCollector.NO_OP_COLLECTOR);
} else {
Collector collector = context.getProfilers() == null
- ? bucketCollector
- : new InternalProfileCollector(bucketCollector, CollectorResult.REASON_AGGREGATION, List.of());
+ ? bucketCollector.asCollector()
+ : new InternalProfileCollector(bucketCollector.asCollector(), CollectorResult.REASON_AGGREGATION, List.of());
context.queryCollectors().put(AggregationPhase.class, collector);
}
}
diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java b/server/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java
index c9c72b3b8ac8e..87052b6cf54ac 100644
--- a/server/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java
+++ b/server/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java
@@ -10,6 +10,7 @@
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Collector;
+import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.ScoreMode;
import java.io.IOException;
@@ -17,9 +18,9 @@
/**
* A Collector that can collect data in separate buckets.
*/
-public abstract class BucketCollector implements Collector {
+public abstract class BucketCollector {
- public static final BucketCollector NO_OP_COLLECTOR = new BucketCollector() {
+ public static final BucketCollector NO_OP_BUCKET_COLLECTOR = new BucketCollector() {
@Override
public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx) {
@@ -41,11 +42,18 @@ public ScoreMode scoreMode() {
}
};
- // TODO: will remove it in a follow up PR
- @Override
- public final LeafBucketCollector getLeafCollector(LeafReaderContext ctx) throws IOException {
- return getLeafCollector(new AggregationExecutionContext(ctx, null, null));
- }
+ public static final Collector NO_OP_COLLECTOR = new Collector() {
+
+ @Override
+ public LeafCollector getLeafCollector(LeafReaderContext context) {
+ return LeafBucketCollector.NO_OP_COLLECTOR;
+ }
+
+ @Override
+ public ScoreMode scoreMode() {
+ return ScoreMode.COMPLETE_NO_SCORES;
+ }
+ };
public abstract LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx) throws IOException;
@@ -59,4 +67,28 @@ public final LeafBucketCollector getLeafCollector(LeafReaderContext ctx) throws
*/
public abstract void postCollection() throws IOException;
+ /**
+ * Indicates what features are required from the scorer.
+ */
+ public abstract ScoreMode scoreMode();
+
+ /**
+ * Return this BucketCollector wrapped as a {@link Collector}
+ */
+ public final Collector asCollector() {
+ return new BucketCollectorWrapper(this);
+ }
+
+ private record BucketCollectorWrapper(BucketCollector bucketCollector) implements Collector {
+
+ @Override
+ public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
+ return bucketCollector.getLeafCollector(new AggregationExecutionContext(context, null, null));
+ }
+
+ @Override
+ public ScoreMode scoreMode() {
+ return bucketCollector.scoreMode();
+ }
+ }
}
diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/MultiBucketCollector.java b/server/src/main/java/org/elasticsearch/search/aggregations/MultiBucketCollector.java
index 657633f774c74..e98762f462243 100644
--- a/server/src/main/java/org/elasticsearch/search/aggregations/MultiBucketCollector.java
+++ b/server/src/main/java/org/elasticsearch/search/aggregations/MultiBucketCollector.java
@@ -23,7 +23,7 @@
/**
* A {@link BucketCollector} which allows running a bucket collection with several
* {@link BucketCollector}s. It is similar to the {@link MultiCollector} except that the
- * {@link #wrap} method filters out the {@link BucketCollector#NO_OP_COLLECTOR}s and not
+ * {@link #wrap} method filters out the {@link BucketCollector#NO_OP_BUCKET_COLLECTOR}s and not
* the null ones.
*/
public class MultiBucketCollector extends BucketCollector {
@@ -31,12 +31,12 @@ public class MultiBucketCollector extends BucketCollector {
* Wraps a list of {@link BucketCollector}s with a {@link MultiBucketCollector}. This
* method works as follows:
*
- * - Filters out the {@link BucketCollector#NO_OP_COLLECTOR}s collectors, so they are not used
+ *
- Filters out the {@link BucketCollector#NO_OP_BUCKET_COLLECTOR}s collectors, so they are not used
* during search time.
*
- If the input contains 1 real collector we wrap it in a collector that takes
* {@code terminateIfNoop} into account.
*
- Otherwise the method returns a {@link MultiBucketCollector} which wraps the
- * non-{@link BucketCollector#NO_OP_COLLECTOR} collectors.
+ * non-{@link BucketCollector#NO_OP_BUCKET_COLLECTOR} collectors.
*
* @param terminateIfNoop Pass true if {@link #getLeafCollector} should throw
* {@link CollectionTerminatedException} if all leaf collectors are noop. Pass
@@ -52,13 +52,13 @@ public static BucketCollector wrap(boolean terminateIfNoop, Iterable extends B
// and dropped from the array we save for actual collection time.
int n = 0;
for (BucketCollector c : collectors) {
- if (c != NO_OP_COLLECTOR) {
+ if (c != NO_OP_BUCKET_COLLECTOR) {
n++;
}
}
if (n == 0) {
- return NO_OP_COLLECTOR;
+ return NO_OP_BUCKET_COLLECTOR;
} else if (n == 1) {
// only 1 Collector - return it.
BucketCollector col = null;
diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java
index dd91224f21819..7d01e7598537f 100644
--- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java
+++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java
@@ -158,7 +158,7 @@ protected void doClose() {
@Override
protected void doPreCollection() throws IOException {
deferredCollectors = MultiBucketCollector.wrap(false, Arrays.asList(subAggregators));
- collectableSubAggregators = BucketCollector.NO_OP_COLLECTOR;
+ collectableSubAggregators = BucketCollector.NO_OP_BUCKET_COLLECTOR;
}
@Override
@@ -170,7 +170,7 @@ protected void doPostCollection() throws IOException {
public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException {
// Composite aggregator must be at the top of the aggregation tree
assert owningBucketOrds.length == 1 && owningBucketOrds[0] == 0L;
- if (deferredCollectors != NO_OP_COLLECTOR) {
+ if (deferredCollectors != NO_OP_BUCKET_COLLECTOR) {
// Replay all documents that contain at least one top bucket (collected during the first pass).
runDeferredCollections();
}
@@ -440,7 +440,7 @@ private void processLeafFromQuery(LeafReaderContext ctx, Sort indexSortPrefix) t
protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException {
finishLeaf();
- boolean fillDocIdSet = deferredCollectors != NO_OP_COLLECTOR;
+ boolean fillDocIdSet = deferredCollectors != NO_OP_BUCKET_COLLECTOR;
Sort indexSortPrefix = buildIndexSortPrefix(aggCtx.getLeafReaderContext());
int sortPrefixLen = computeSortPrefixLen(indexSortPrefix);
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/MultiBucketCollectorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/MultiBucketCollectorTests.java
index 773466716dff0..7f244bfaf2431 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/MultiBucketCollectorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/MultiBucketCollectorTests.java
@@ -176,7 +176,7 @@ public void testCollectionTerminatedExceptionHandling() throws IOException {
expectedCounts.put(collector, expectedCount);
collectors.add(new TerminateAfterBucketCollector(collector, terminateAfter));
}
- searcher.search(new MatchAllDocsQuery(), MultiBucketCollector.wrap(true, collectors));
+ searcher.search(new MatchAllDocsQuery(), MultiBucketCollector.wrap(true, collectors).asCollector());
for (Map.Entry expectedCount : expectedCounts.entrySet()) {
assertEquals(expectedCount.getValue().intValue(), expectedCount.getKey().getTotalHits());
}
@@ -252,7 +252,7 @@ public void testSetScorerAfterCollectionTerminated() throws IOException {
Collections.shuffle(collectors, random());
BucketCollector collector = MultiBucketCollector.wrap(true, collectors);
- LeafBucketCollector leafCollector = collector.getLeafCollector((LeafReaderContext) null);
+ LeafBucketCollector leafCollector = collector.getLeafCollector(null);
leafCollector.setScorer(scorer);
assertTrue(setScorerCalled1.get());
assertTrue(setScorerCalled2.get());
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/BestBucketsDeferringCollectorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/BestBucketsDeferringCollectorTests.java
index f1b6fa6488f5c..2f9b8a1fd9e92 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/BestBucketsDeferringCollectorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/BestBucketsDeferringCollectorTests.java
@@ -14,7 +14,9 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
@@ -72,7 +74,7 @@ public ScoreMode scoreMode() {
Set deferredCollectedDocIds = new HashSet<>();
collector.setDeferredCollector(Collections.singleton(bla(deferredCollectedDocIds)));
collector.preCollection();
- indexSearcher.search(termQuery, collector);
+ indexSearcher.search(termQuery, collector.asCollector());
collector.postCollection();
collector.prepareSelectedBuckets(0);
@@ -86,7 +88,7 @@ public ScoreMode scoreMode() {
deferredCollectedDocIds = new HashSet<>();
collector.setDeferredCollector(Collections.singleton(bla(deferredCollectedDocIds)));
collector.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), collector);
+ indexSearcher.search(new MatchAllDocsQuery(), collector.asCollector());
collector.postCollection();
collector.prepareSelectedBuckets(0);
@@ -199,21 +201,17 @@ private void testCase(
CollectingBucketCollector finalCollector = new CollectingBucketCollector();
deferringCollector.setDeferredCollector(Collections.singleton(finalCollector));
deferringCollector.preCollection();
- indexSearcher.search(query, new BucketCollector() {
+ indexSearcher.search(query, new Collector() {
@Override
public ScoreMode scoreMode() {
return ScoreMode.COMPLETE_NO_SCORES;
}
@Override
- public void preCollection() throws IOException {}
-
- @Override
- public void postCollection() throws IOException {}
-
- @Override
- public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx) throws IOException {
- LeafBucketCollector delegate = deferringCollector.getLeafCollector(aggCtx);
+ public LeafBucketCollector getLeafCollector(LeafReaderContext context) throws IOException {
+ LeafBucketCollector delegate = deferringCollector.getLeafCollector(
+ new AggregationExecutionContext(context, null, null)
+ );
return leafCollector.apply(deferringCollector, delegate);
}
});
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/filter/FiltersAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/filter/FiltersAggregatorTests.java
index ad80997a1d588..0f781d857f86f 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/filter/FiltersAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/filter/FiltersAggregatorTests.java
@@ -669,7 +669,7 @@ public void onCache(ShardId shardId, Accountable accountable) {}
AggregationContext context = createAggregationContext(searcher, new MatchAllDocsQuery());
FilterByFilterAggregator aggregator = createAggregator(builder, context);
aggregator.preCollection();
- searcher.search(context.query(), aggregator);
+ searcher.search(context.query(), aggregator.asCollector());
aggregator.postCollection();
InternalAggregation result = aggregator.buildTopLevel();
@@ -746,7 +746,7 @@ public void onCache(ShardId shardId, Accountable accountable) {}
AggregationContext context = createAggregationContext(searcher, new MatchAllDocsQuery(), ft);
FilterByFilterAggregator aggregator = createAggregator(builder, context);
aggregator.preCollection();
- searcher.search(context.query(), aggregator);
+ searcher.search(context.query(), aggregator.asCollector());
aggregator.postCollection();
InternalAggregation result = aggregator.buildTopLevel();
@@ -812,7 +812,7 @@ public void onCache(ShardId shardId, Accountable accountable) {}
AggregationContext context = createAggregationContext(searcher, new MatchAllDocsQuery(), ft);
FilterByFilterAggregator aggregator = createAggregator(builder, context);
aggregator.preCollection();
- searcher.search(context.query(), aggregator);
+ searcher.search(context.query(), aggregator.asCollector());
aggregator.postCollection();
InternalAggregation result = aggregator.buildTopLevel();
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java
index e7fdea0de06b1..d9830cd436714 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java
@@ -1038,7 +1038,7 @@ private void aggregationImplementationChoiceTestCase(
}
assertThat(agg, matcher);
agg.preCollection();
- context.searcher().search(context.query(), agg);
+ context.searcher().search(context.query(), agg.asCollector());
InternalDateHistogram result = (InternalDateHistogram) agg.buildTopLevel();
result = (InternalDateHistogram) result.reduce(
List.of(result),
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/sampler/BestDocsDeferringCollectorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/sampler/BestDocsDeferringCollectorTests.java
index 060a3b0befbb0..fab44274d558a 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/sampler/BestDocsDeferringCollectorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/sampler/BestDocsDeferringCollectorTests.java
@@ -65,7 +65,7 @@ public void testReplay() throws Exception {
Set deferredCollectedDocIds = new HashSet<>();
collector.setDeferredCollector(Collections.singleton(testCollector(deferredCollectedDocIds)));
collector.preCollection();
- indexSearcher.search(termQuery, collector);
+ indexSearcher.search(termQuery, collector.asCollector());
collector.postCollection();
collector.prepareSelectedBuckets(0);
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorTests.java
index 6048d4760a115..e52c6539f4ef4 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorTests.java
@@ -250,7 +250,7 @@ public void testUnmapped() throws Exception {
RareTermsAggregationBuilder aggregationBuilder = new RareTermsAggregationBuilder("_name").field(fieldNames[i]);
Aggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType1, fieldType2);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
RareTerms result = (RareTerms) aggregator.buildTopLevel();
assertEquals("_name", result.getName());
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java
index 3aab0c7983e93..5bddf4967a0cf 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java
@@ -692,7 +692,7 @@ public void testNumericIncludeExclude() throws Exception {
AggregationContext context = createAggregationContext(indexSearcher, null, fieldType);
TermsAggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(2, result.getBuckets().size());
@@ -710,7 +710,7 @@ public void testNumericIncludeExclude() throws Exception {
context = createAggregationContext(indexSearcher, null, fieldType);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(4, result.getBuckets().size());
@@ -735,7 +735,7 @@ public void testNumericIncludeExclude() throws Exception {
context = createAggregationContext(indexSearcher, null, fieldType);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(2, result.getBuckets().size());
@@ -755,7 +755,7 @@ public void testNumericIncludeExclude() throws Exception {
context = createAggregationContext(indexSearcher, null, fieldType);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(4, result.getBuckets().size());
@@ -930,7 +930,7 @@ private void termsAggregator(
AggregationContext context = createAggregationContext(indexSearcher, new MatchAllDocsQuery(), fieldType);
Aggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(size, result.getBuckets().size());
@@ -958,7 +958,7 @@ private void termsAggregator(
context = createAggregationContext(indexSearcher, new MatchAllDocsQuery(), fieldType, filterFieldType);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
result = ((Filter) reduce(aggregationBuilder, aggregator, context.bigArrays())).getAggregations().get("_name2");
int expectedFilteredCounts = 0;
@@ -1038,7 +1038,7 @@ private void termsAggregatorWithNestedMaxAgg(
AggregationContext context = createAggregationContext(indexSearcher, new MatchAllDocsQuery(), fieldType, fieldType2);
Aggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(size, result.getBuckets().size());
@@ -1065,7 +1065,7 @@ public void testEmpty() throws Exception {
AggregationContext context = createAggregationContext(indexSearcher, null, fieldType1);
Aggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals("_name", result.getName());
@@ -1075,7 +1075,7 @@ public void testEmpty() throws Exception {
context = createAggregationContext(indexSearcher, null, fieldType2);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals("_name", result.getName());
@@ -1085,7 +1085,7 @@ public void testEmpty() throws Exception {
context = createAggregationContext(indexSearcher, null, fieldType3);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals("_name", result.getName());
@@ -1108,7 +1108,7 @@ public void testUnmapped() throws Exception {
AggregationContext context = createAggregationContext(indexSearcher, null);
Aggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals("_name", result.getName());
@@ -1144,7 +1144,7 @@ public void testUnmappedWithMissing() throws Exception {
AggregationContext context = createAggregationContext(indexSearcher, new MatchAllDocsQuery(), fieldType1);
Aggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals("_name", result.getName());
@@ -1260,7 +1260,7 @@ public void testNestedTermsAgg() throws Exception {
AggregationContext context = createAggregationContext(indexSearcher, new MatchAllDocsQuery(), fieldType1, fieldType2);
Aggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms result = reduce(aggregationBuilder, aggregator, context.bigArrays());
assertEquals(3, result.getBuckets().size());
@@ -2325,7 +2325,7 @@ private InternalAggregation buildInternalAggregation(TermsAggregationBuilder bui
throws IOException {
TermsAggregator aggregator = createAggregator(builder, searcher, fieldType);
aggregator.preCollection();
- searcher.search(new MatchAllDocsQuery(), aggregator);
+ searcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
return aggregator.buildTopLevel();
}
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorTests.java
index 81555d8a8ebdc..4dd7de7e0761a 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorTests.java
@@ -283,7 +283,7 @@ public void testSingleValuedFieldPartiallyUnmapped() throws IOException {
AvgAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
InternalAvg avg = (InternalAvg) aggregator.buildAggregation(0L);
@@ -544,7 +544,7 @@ public void testOrderByEmptyAggregation() throws IOException {
TermsAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms terms = (Terms) aggregator.buildTopLevel();
@@ -616,7 +616,7 @@ public void testCacheAggregation() throws IOException {
AggregationContext context = createAggregationContext(indexSearcher, null, fieldType);
AvgAggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
InternalAvg avg = (InternalAvg) aggregator.buildAggregation(0L);
@@ -662,7 +662,7 @@ public void testScriptCaching() throws IOException {
AggregationContext context = createAggregationContext(indexSearcher, null, fieldType);
AvgAggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
InternalAvg avg = (InternalAvg) aggregator.buildAggregation(0L);
@@ -680,7 +680,7 @@ public void testScriptCaching() throws IOException {
context = createAggregationContext(indexSearcher, null, fieldType);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
avg = (InternalAvg) aggregator.buildAggregation(0L);
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorTests.java
index 64baf8d4e4b18..f13de38e5a720 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorTests.java
@@ -432,7 +432,7 @@ public void testSingleValuedFieldPartiallyUnmapped() throws IOException {
final CardinalityAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
final InternalCardinality cardinality = (InternalCardinality) aggregator.buildAggregation(0L);
@@ -642,7 +642,7 @@ public void testCacheAggregation() throws IOException {
final AggregationContext context = createAggregationContext(indexSearcher, null, fieldType);
final CardinalityAggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
final InternalCardinality cardinality = (InternalCardinality) aggregator.buildAggregation(0L);
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java
index c8cae2f879149..e952546e0e8ac 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java
@@ -207,7 +207,7 @@ private void testCase(
HDRPercentilesAggregator aggregator = createAggregator(builder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(query, aggregator);
+ indexSearcher.search(query, aggregator.asCollector());
aggregator.postCollection();
verify.accept((InternalHDRPercentiles) aggregator.buildAggregation(0L));
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorTests.java
index c01363c81c195..ca200c95acef5 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorTests.java
@@ -441,7 +441,7 @@ public void testSingleValuedFieldGetProperty() throws IOException {
GlobalAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Global global = (Global) aggregator.buildTopLevel();
@@ -486,7 +486,7 @@ public void testSingleValuedFieldPartiallyUnmapped() throws IOException {
MaxAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Max max = (Max) aggregator.buildAggregation(0L);
@@ -695,7 +695,7 @@ public void testEmptyAggregation() throws Exception {
GlobalAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Global global = (Global) aggregator.buildTopLevel();
@@ -737,7 +737,7 @@ public void testOrderByEmptyAggregation() throws IOException {
TermsAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Terms terms = (Terms) aggregator.buildTopLevel();
@@ -790,7 +790,7 @@ public void testEarlyTermination() throws Exception {
BucketCollector bucketCollector = MultiBucketCollector.wrap(true, List.of(maxAggregator, countAggregator));
bucketCollector.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), bucketCollector);
+ indexSearcher.search(new MatchAllDocsQuery(), bucketCollector.asCollector());
bucketCollector.postCollection();
Max max = (Max) maxAggregator.buildAggregation(0L);
@@ -840,7 +840,7 @@ public void testNestedEarlyTermination() throws Exception {
BucketCollector bucketCollector = MultiBucketCollector.wrap(true, List.of(maxAggregator, countAggregator, termsAggregator));
bucketCollector.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), bucketCollector);
+ indexSearcher.search(new MatchAllDocsQuery(), bucketCollector.asCollector());
bucketCollector.postCollection();
Max max = (Max) maxAggregator.buildTopLevel();
@@ -896,7 +896,7 @@ public void testCacheAggregation() throws IOException {
AggregationContext context = createAggregationContext(indexSearcher, null, fieldType);
MaxAggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Max max = (Max) aggregator.buildAggregation(0L);
@@ -942,7 +942,7 @@ public void testScriptCaching() throws Exception {
AggregationContext context = createAggregationContext(indexSearcher, null, fieldType);
MaxAggregator aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
Max max = (Max) aggregator.buildAggregation(0L);
@@ -959,7 +959,7 @@ public void testScriptCaching() throws Exception {
context = createAggregationContext(indexSearcher, null, fieldType);
aggregator = createAggregator(aggregationBuilder, context);
aggregator.preCollection();
- indexSearcher.search(new MatchAllDocsQuery(), aggregator);
+ indexSearcher.search(new MatchAllDocsQuery(), aggregator.asCollector());
aggregator.postCollection();
max = (Max) aggregator.buildAggregation(0L);
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java
index 799cf72d82f62..bdd2604715ca8 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java
@@ -182,7 +182,7 @@ private void testCase(
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
TDigestPercentilesAggregator aggregator = createAggregator(builder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(query, aggregator);
+ indexSearcher.search(query, aggregator.asCollector());
aggregator.postCollection();
verify.accept((InternalTDigestPercentiles) aggregator.buildAggregation(0L));
}
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java
index 3776515c72cfa..c58fffc4777a4 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java
@@ -531,7 +531,7 @@ private void testCase(
MappedFieldType fieldType2 = new NumberFieldMapper.NumberFieldType("weight_field", fieldNumberType);
WeightedAvgAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType, fieldType2);
aggregator.preCollection();
- indexSearcher.search(query, aggregator);
+ indexSearcher.search(query, aggregator.asCollector());
aggregator.postCollection();
verify.accept((InternalWeightedAvg) aggregator.buildAggregation(0L));
} finally {
diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java
index 498aa0d28a941..885f287c27351 100644
--- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java
@@ -574,7 +574,7 @@ private A searchAndReduce(
new TimeSeriesIndexSearcher(subSearcher, List.of()).search(rewritten, a);
} else {
Weight weight = subSearcher.createWeight(rewritten, ScoreMode.COMPLETE, 1f);
- subSearcher.search(weight, a);
+ subSearcher.search(weight, a.asCollector());
}
a.postCollection();
aggs.add(a.buildTopLevel());
@@ -584,7 +584,7 @@ private A searchAndReduce(
if (context.isInSortOrderExecutionRequired()) {
new TimeSeriesIndexSearcher(searcher, List.of()).search(rewritten, MultiBucketCollector.wrap(true, List.of(root)));
} else {
- searcher.search(rewritten, MultiBucketCollector.wrap(true, List.of(root)));
+ searcher.search(rewritten, MultiBucketCollector.wrap(true, List.of(root)).asCollector());
}
root.postCollection();
aggs.add(root.buildTopLevel());
@@ -753,7 +753,7 @@ protected void debugTestCase(
);
Aggregator aggregator = createAggregator(builder, context);
aggregator.preCollection();
- searcher.search(context.query(), aggregator);
+ searcher.search(context.query(), aggregator.asCollector());
aggregator.postCollection();
InternalAggregation r = aggregator.buildTopLevel();
r = r.reduce(
diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java
index 5c798b80ca09c..43effda31a02c 100644
--- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java
@@ -342,7 +342,7 @@ private void testCase(
Aggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType);
aggregator.preCollection();
- indexSearcher.search(query, aggregator);
+ indexSearcher.search(query, aggregator.asCollector());
aggregator.postCollection();
@SuppressWarnings("unchecked")
InternalGeoGrid topLevel = (InternalGeoGrid) aggregator.buildTopLevel();
diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HDRPreAggregatedPercentilesAggregatorTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HDRPreAggregatedPercentilesAggregatorTests.java
index 31c5ea233bebe..09a3f662e4db2 100644
--- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HDRPreAggregatedPercentilesAggregatorTests.java
+++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HDRPreAggregatedPercentilesAggregatorTests.java
@@ -152,7 +152,7 @@ private void testCase(Query query, CheckedConsumer) aggregator.buildTopLevel());