Skip to content

Commit

Permalink
include keyword/numeric terms without any metric aggregations as well
Browse files Browse the repository at this point in the history
Signed-off-by: Sandesh Kumar <[email protected]>
  • Loading branch information
sandeshkr419 committed Feb 17, 2025
1 parent e5243f5 commit 7a0a94a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws
if (supportedStarTree != null) {
StarTreeBucketCollector starTreeBucketCollector = getStarTreeBucketCollector(ctx, supportedStarTree, null);
StarTreeQueryHelper.preComputeBucketsWithStarTree(starTreeBucketCollector);
return true;
}
return filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, segmentMatchAll(context, ctx));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ boolean tryCollectFromTermFrequencies(LeafReaderContext ctx, SortedSetDocValues
@Override
protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
SortedSetDocValues globalOrds = valuesSource.globalOrdinalsValues(ctx);
CompositeIndexFieldInfo supportedStarTree = StarTreeQueryHelper.getSupportedStarTree(this.context.getQueryShardContext());
if (supportedStarTree != null) {
globalOperator = valuesSource.globalOrdinalsMapping(ctx);
StarTreeBucketCollector starTreeBucketCollector = getStarTreeBucketCollector(ctx, supportedStarTree, null);
StarTreeQueryHelper.preComputeBucketsWithStarTree(starTreeBucketCollector);
return true;
}
if (collectionStrategy instanceof DenseGlobalOrds
&& this.resultStrategy instanceof StandardTermsResults
&& subAggregators.length == 0) {
Expand All @@ -239,12 +246,6 @@ protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws
(ord, docCount) -> incrementBucketDocCount(collectionStrategy.globalOrdToBucketOrd(0, ord), docCount)
);
}
CompositeIndexFieldInfo supportedStarTree = StarTreeQueryHelper.getSupportedStarTree(this.context.getQueryShardContext());
if (supportedStarTree != null) {
globalOperator = valuesSource.globalOrdinalsMapping(ctx);
StarTreeBucketCollector starTreeBucketCollector = getStarTreeBucketCollector(ctx, supportedStarTree, null);
StarTreeQueryHelper.preComputeBucketsWithStarTree(starTreeBucketCollector);
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws
if (supportedStarTree != null) {
StarTreeBucketCollector starTreeBucketCollector = getStarTreeBucketCollector(ctx, supportedStarTree, null);
StarTreeQueryHelper.preComputeBucketsWithStarTree(starTreeBucketCollector);
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public void testStarTreeKeywordTerms() throws IOException {
supportedDimensions.put(new NumericDimension(SIZE), SIZE_FIELD_NAME);
supportedDimensions.put(new OrdinalDimension(CLIENTIP), CLIENTIP_FIELD_NAME);

Query query = new MatchAllDocsQuery();
QueryBuilder queryBuilder = null;
TermsAggregationBuilder termsAggregationBuilder = terms("terms_agg").field(CLIENTIP)
.collectMode(Aggregator.SubAggCollectionMode.BREADTH_FIRST);
testCase(indexSearcher, query, queryBuilder, termsAggregationBuilder, starTree, supportedDimensions);

ValuesSourceAggregationBuilder[] aggBuilders = {
sum("_sum").field(SIZE),
max("_max").field(SIZE),
Expand All @@ -160,10 +166,10 @@ public void testStarTreeKeywordTerms() throws IOException {
avg("_avg").field(SIZE) };

for (ValuesSourceAggregationBuilder aggregationBuilder : aggBuilders) {
Query query = new MatchAllDocsQuery();
QueryBuilder queryBuilder = null;
query = new MatchAllDocsQuery();
queryBuilder = null;

TermsAggregationBuilder termsAggregationBuilder = terms("terms_agg").field(CLIENTIP)
termsAggregationBuilder = terms("terms_agg").field(CLIENTIP)
.subAggregation(aggregationBuilder)
.collectMode(Aggregator.SubAggCollectionMode.BREADTH_FIRST);
testCase(indexSearcher, query, queryBuilder, termsAggregationBuilder, starTree, supportedDimensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void testStarTreeNumericTerms() throws IOException {
supportedDimensions.put(new NumericDimension(STATUS), STATUS_FIELD_TYPE);
supportedDimensions.put(new NumericDimension(SIZE), SIZE_FIELD_NAME);

Query query = new MatchAllDocsQuery();
QueryBuilder queryBuilder = null;
TermsAggregationBuilder termsAggregationBuilder = terms("terms_agg").field(STATUS);
testCase(indexSearcher, query, queryBuilder, termsAggregationBuilder, starTree, supportedDimensions);

ValuesSourceAggregationBuilder[] aggBuilders = {
sum("_sum").field(SIZE),
max("_max").field(SIZE),
Expand All @@ -148,10 +153,9 @@ public void testStarTreeNumericTerms() throws IOException {
avg("_avg").field(SIZE) };

for (ValuesSourceAggregationBuilder aggregationBuilder : aggBuilders) {
Query query = new MatchAllDocsQuery();
QueryBuilder queryBuilder = null;

TermsAggregationBuilder termsAggregationBuilder = terms("terms_agg").field(STATUS).subAggregation(aggregationBuilder);
query = new MatchAllDocsQuery();
queryBuilder = null;
termsAggregationBuilder = terms("terms_agg").field(STATUS).subAggregation(aggregationBuilder);
testCase(indexSearcher, query, queryBuilder, termsAggregationBuilder, starTree, supportedDimensions);

// Numeric-terms query with numeric terms aggregation
Expand Down Expand Up @@ -181,10 +185,10 @@ public void testStarTreeNumericTerms() throws IOException {
avg("_avg").field(STATUS) };

for (ValuesSourceAggregationBuilder aggregationBuilder : aggBuilders) {
Query query = new MatchAllDocsQuery();
QueryBuilder queryBuilder = null;
query = new MatchAllDocsQuery();
queryBuilder = null;

TermsAggregationBuilder termsAggregationBuilder = terms("terms_agg").field(SIZE).subAggregation(aggregationBuilder);
termsAggregationBuilder = terms("terms_agg").field(SIZE).subAggregation(aggregationBuilder);
testCase(indexSearcher, query, queryBuilder, termsAggregationBuilder, starTree, supportedDimensions);
}

Expand Down

0 comments on commit 7a0a94a

Please sign in to comment.