diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/DateHistogramAggregatorBridge.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/DateHistogramAggregatorBridge.java index 5e694c2066f71..c780732a5ddce 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/DateHistogramAggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/DateHistogramAggregatorBridge.java @@ -11,8 +11,6 @@ import org.apache.lucene.document.LongPoint; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PointValues; -import org.apache.lucene.search.ScoreMode; -import org.apache.lucene.search.Weight; import org.opensearch.common.Rounding; import org.opensearch.index.mapper.DateFieldMapper; import org.opensearch.index.mapper.MappedFieldType; diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/RangeAggregatorBridge.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/RangeAggregatorBridge.java index 25216c56d48b0..fc1bcd83f2c1b 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/RangeAggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/RangeAggregatorBridge.java @@ -10,14 +10,11 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PointValues; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; import org.opensearch.index.mapper.MappedFieldType; import org.opensearch.index.mapper.NumericPointEncoder; import org.opensearch.search.aggregations.bucket.range.RangeAggregator; import org.opensearch.search.aggregations.support.ValuesSource; import org.opensearch.search.aggregations.support.ValuesSourceConfig; -import org.opensearch.search.internal.SearchContext; import java.io.IOException; import java.util.function.BiConsumer; diff --git a/server/src/test/java/org/opensearch/search/aggregations/bucket/range/RangeAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/bucket/range/RangeAggregatorTests.java index 36bc6bcd1cdb9..630326967aae1 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/bucket/range/RangeAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/bucket/range/RangeAggregatorTests.java @@ -539,7 +539,8 @@ public void testTopLevelFilterTermQuery() throws IOException { Query boolQuery = builder.build(); List docList = new ArrayList<>(); - for (int i = 0; i < 3; i++) docList.add(new Document()); + for (int i = 0; i < 3; i++) + docList.add(new Document()); docList.get(0).addAll(numType.createFields(numType.typeName(), 3.0, true, true, false)); docList.get(1).addAll(numType.createFields(numType.typeName(), 11.0, true, true, false)); @@ -548,22 +549,15 @@ public void testTopLevelFilterTermQuery() throws IOException { docList.get(1).add(new KeywordField(KEYWORD_FIELD_NAME, "route1", Field.Store.NO)); docList.get(2).add(new KeywordField(KEYWORD_FIELD_NAME, "route2", Field.Store.NO)); - testRewriteOptimizationCase( - NUM_FIELD_TYPE, - new double[][] { { 0.0, 10.0 }, { 10.0, 20.0 } }, - boolQuery, - docList, - range -> { - List ranges = range.getBuckets(); - assertEquals(2, ranges.size()); - assertEquals("0.0-10.0", ranges.get(0).getKeyAsString()); - assertEquals(1, ranges.get(0).getDocCount()); - assertEquals("10.0-20.0", ranges.get(1).getKeyAsString()); - assertEquals(1, ranges.get(1).getDocCount()); - assertTrue(AggregationInspectionHelper.hasValue(range)); - }, - false - ); + testRewriteOptimizationCase(NUM_FIELD_TYPE, new double[][] { { 0.0, 10.0 }, { 10.0, 20.0 } }, boolQuery, docList, range -> { + List ranges = range.getBuckets(); + assertEquals(2, ranges.size()); + assertEquals("0.0-10.0", ranges.get(0).getKeyAsString()); + assertEquals(1, ranges.get(0).getDocCount()); + assertEquals("10.0-20.0", ranges.get(1).getKeyAsString()); + assertEquals(1, ranges.get(1).getDocCount()); + assertTrue(AggregationInspectionHelper.hasValue(range)); + }, false); } /** @@ -580,7 +574,8 @@ public void testTopLevelEffectiveMatchAll() throws IOException { Query boolQuery = builder.build(); List docList = new ArrayList<>(); - for (int i = 0; i < 3; i++) docList.add(new Document()); + for (int i = 0; i < 3; i++) + docList.add(new Document()); docList.get(0).addAll(numType.createFields(numType.typeName(), 3.0, true, true, false)); docList.get(1).addAll(numType.createFields(numType.typeName(), 11.0, true, true, false)); @@ -589,22 +584,15 @@ public void testTopLevelEffectiveMatchAll() throws IOException { docList.get(1).add(new KeywordField(KEYWORD_FIELD_NAME, "route1", Field.Store.NO)); docList.get(2).add(new KeywordField(KEYWORD_FIELD_NAME, "route1", Field.Store.NO)); - testRewriteOptimizationCase( - NUM_FIELD_TYPE, - new double[][]{{0.0, 10.0}, {10.0, 20.0}}, - boolQuery, - docList, - range -> { - List ranges = range.getBuckets(); - assertEquals(2, ranges.size()); - assertEquals("0.0-10.0", ranges.get(0).getKeyAsString()); - assertEquals(1, ranges.get(0).getDocCount()); - assertEquals("10.0-20.0", ranges.get(1).getKeyAsString()); - assertEquals(2, ranges.get(1).getDocCount()); - assertTrue(AggregationInspectionHelper.hasValue(range)); - }, - true - ); + testRewriteOptimizationCase(NUM_FIELD_TYPE, new double[][] { { 0.0, 10.0 }, { 10.0, 20.0 } }, boolQuery, docList, range -> { + List ranges = range.getBuckets(); + assertEquals(2, ranges.size()); + assertEquals("0.0-10.0", ranges.get(0).getKeyAsString()); + assertEquals(1, ranges.get(0).getDocCount()); + assertEquals("10.0-20.0", ranges.get(1).getKeyAsString()); + assertEquals(2, ranges.get(1).getDocCount()); + assertTrue(AggregationInspectionHelper.hasValue(range)); + }, true); } private void testCase( @@ -675,7 +663,8 @@ private void testRewriteOptimizationCase( for (Number dataPoint : dataPoints) { Document doc = new Document(); List fieldList = numberType.createFields(fieldName, dataPoint, true, true, false); - for (Field fld : fieldList) doc.add(fld); + for (Field fld : fieldList) + doc.add(fld); docs.add(doc); }