diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java index b178d7ede9aa3..22f0606276161 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java @@ -38,7 +38,6 @@ import org.opensearch.search.internal.SearchContext; import java.io.IOException; -import java.time.Instant; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; @@ -272,7 +271,7 @@ public void setAggregationType(AggregationType aggregationType) { } public boolean isRewriteable(final Object parent, final int subAggLength) { - if (context.maxAggRewriteFilters() == 0) return false; + // if (context.maxAggRewriteFilters() == 0) return false; boolean rewriteable = aggregationType.isRewriteable(parent, subAggLength); logger.debug("Fast filter rewriteable: {} for shard {}", rewriteable, context.indexShard().shardId()); @@ -331,9 +330,11 @@ interface AggregationType { boolean isRewriteable(Object parent, int subAggLength); Weight[] buildFastFilter(SearchContext ctx) throws IOException; + Weight[] buildFastFilter(LeafReaderContext leaf, SearchContext ctx) throws IOException; long[][] buildRanges(SearchContext ctx) throws IOException; + long[][] buildRanges(LeafReaderContext leaf, SearchContext ctx) throws IOException; default int getSize() { @@ -515,6 +516,7 @@ public static boolean tryFastFilterAggregation( if (ctx.reader().hasDeletions()) return false; PointValues values = ctx.reader().getPointValues(fastFilterContext.fieldName); + if (values == null) return false; // date field is 1 dimensional // only proceed if every document has exactly one point for this field if (values.getDocCount() != values.size()) return false; @@ -551,13 +553,7 @@ public static boolean tryFastFilterAggregation( final DateFieldMapper.DateFieldType fieldType = ((AbstractDateHistogramAggregationType) fastFilterContext.aggregationType) .getFieldType(); int size = fastFilterContext.aggregationType.getSize(); - DebugInfoCollector debugInfo = multiRangesTraverse( - values.getPointTree(), - ranges, - incrementDocCount, - fieldType, - size - ); + DebugInfoCollector debugInfo = multiRangesTraverse(values.getPointTree(), ranges, incrementDocCount, fieldType, size); fastFilterContext.consumeDebugInfo(debugInfo); logger.debug("Fast filter optimization applied to shard {} segment {}", fastFilterContext.context.indexShard().shardId(), ctx.ord); diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java index a8c6ae6ec0c39..786e7e47537b9 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java @@ -171,6 +171,7 @@ final class CompositeAggregator extends BucketsAggregator { // bucketOrds is used for saving date histogram results bucketOrds = LongKeyedBucketOrds.build(context.bigArrays(), CardinalityUpperBound.ONE); preparedRounding = ((CompositeAggregationType) fastFilterContext.getAggregationType()).getRoundingPrepared(); + fastFilterContext.setFieldName(sourceConfigs[0].name()); fastFilterContext.buildRanges(); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java index 75337a1d11ecf..9e59f33fef104 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java @@ -166,6 +166,7 @@ private AutoDateHistogramAggregator( ) ); if (fastFilterContext.isRewriteable(parent, subAggregators.length)) { + fastFilterContext.setFieldName(valuesSourceConfig.fieldType().name()); fastFilterContext.buildRanges(); } } diff --git a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java index 50ea783fe204f..3858bae629ad3 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java @@ -822,7 +822,6 @@ public void testNanosIntervalSecond() throws IOException { aggregation -> aggregation.calendarInterval(DateHistogramInterval.SECOND).field(AGGREGABLE_DATE).minDocCount(1L), histogram -> { List buckets = histogram.getBuckets(); - System.out.println(buckets); assertEquals(3, buckets.size()); Histogram.Bucket bucket = buckets.get(0);