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 f201c27da0b66..dd52168634cfa 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 @@ -213,8 +213,8 @@ public static void buildFastFilterContext( * Encapsulates metadata about a value source needed to rewrite */ public static class FastFilterContext { - private final boolean missing; - private final boolean hasScript; + private boolean missing = false; + private boolean hasScript = false; private final MappedFieldType fieldType; private long afterKey = -1L; @@ -222,13 +222,9 @@ public static class FastFilterContext { private Weight[] filters = null; /** - * @param missing whether missing value/bucket is set - * @param hasScript whether script is used * @param fieldType null if the field doesn't exist */ - public FastFilterContext(boolean missing, boolean hasScript, MappedFieldType fieldType) { - this.missing = missing; - this.hasScript = hasScript; + public FastFilterContext(MappedFieldType fieldType) { this.fieldType = fieldType; } @@ -248,6 +244,11 @@ public void setAfterKey(long afterKey) { this.afterKey = afterKey; } + public void setMissingAndHasScript(boolean missing, boolean hasScript) { + this.missing = missing; + this.hasScript = hasScript; + } + /** * The pre-conditions to initiate fast filter optimization on aggregations are: * 1. The query with aggregation has to be PointRangeQuery on the same date field 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 01a2441db83b8..cd43ce45f901d 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 @@ -169,10 +169,12 @@ final class CompositeAggregator extends BucketsAggregator { bucketOrds = LongKeyedBucketOrds.build(context.bigArrays(), CardinalityUpperBound.ONE); preparedRounding = dateHistogramSource.getPreparedRounding(); fastFilterContext = new FastFilterRewriteHelper.FastFilterContext( - sourceConfigs[0].missingBucket(), - sourceConfigs[0].hasScript(), sourceConfigs[0].fieldType() ); + fastFilterContext.setMissingAndHasScript( + sourceConfigs[0].missingBucket(), + sourceConfigs[0].hasScript() + ); if (rawAfterKey != null) { assert rawAfterKey.size() == 1 && formats.size() == 1; long afterValue = formats.get(0).parseLong(rawAfterKey.get(0).toString(), false, () -> { diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/filter/FiltersAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/filter/FiltersAggregator.java index 7b86d0ed15cf8..04be687b1bb57 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/filter/FiltersAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/filter/FiltersAggregator.java @@ -51,6 +51,7 @@ import org.opensearch.search.aggregations.LeafBucketCollector; import org.opensearch.search.aggregations.LeafBucketCollectorBase; import org.opensearch.search.aggregations.bucket.BucketsAggregator; +import org.opensearch.search.aggregations.bucket.FastFilterRewriteHelper; import org.opensearch.search.internal.SearchContext; import java.io.IOException; 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 c703706630fe6..95d454e785f63 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 @@ -157,10 +157,12 @@ private AutoDateHistogramAggregator( this.preparedRounding = prepareRounding(0); fastFilterContext = new FastFilterRewriteHelper.FastFilterContext( - valuesSourceConfig.missing() != null, - valuesSourceConfig.script() != null, valuesSourceConfig.fieldType() ); + fastFilterContext.setMissingAndHasScript( + valuesSourceConfig.missing() != null, + valuesSourceConfig.script() != null + ); if (fastFilterContext.isRewriteable(parent, subAggregators.length)) { FastFilterRewriteHelper.buildFastFilterContext( context, diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java index 7e7a0b5221d49..5786cbeb7ec12 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java @@ -116,10 +116,12 @@ class DateHistogramAggregator extends BucketsAggregator implements SizedBucketAg bucketOrds = LongKeyedBucketOrds.build(context.bigArrays(), cardinality); fastFilterContext = new FastFilterRewriteHelper.FastFilterContext( - valuesSourceConfig.missing() != null, - valuesSourceConfig.script() != null, valuesSourceConfig.fieldType() ); + fastFilterContext.setMissingAndHasScript( + valuesSourceConfig.missing() != null, + valuesSourceConfig.script() != null + ); if (fastFilterContext.isRewriteable(parent, subAggregators.length)) { FastFilterRewriteHelper.buildFastFilterContext( context,