Skip to content

Commit

Permalink
Fix ignoring missing values in min/max aggregations (#48970)
Browse files Browse the repository at this point in the history
Fixes the issue when the missing values can be ignored in min/max
due to BKD optimization.

Fixes #48905
  • Loading branch information
imotov committed Nov 15, 2019
1 parent 50139b8 commit 9b33165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static Function<byte[], Number> getPointReaderOrNull(SearchContext context, Aggr
if (parent != null) {
return null;
}
if (config.fieldContext() != null && config.script() == null) {
if (config.fieldContext() != null && config.script() == null && config.missing() == null) {
MappedFieldType fieldType = config.fieldContext().fieldType();
if (fieldType == null || fieldType.indexOptions() == IndexOptions.NONE) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import java.util.function.Function;
import java.util.function.Supplier;

import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -232,6 +233,22 @@ public void testUnmappedWithMissingField() throws IOException {
}, null);
}

public void testMissingFieldOptimization() throws IOException {
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.INTEGER);
fieldType.setName("number");

MaxAggregationBuilder aggregationBuilder = new MaxAggregationBuilder("_name").field("number").missing(19L);

testCase(aggregationBuilder, new MatchAllDocsQuery(), iw -> {
iw.addDocument(Arrays.asList(new IntPoint("number", 7), new SortedNumericDocValuesField("number", 7)));
iw.addDocument(Arrays.asList(new IntPoint("number", 1), new SortedNumericDocValuesField("number", 1)));
iw.addDocument(emptyList());
}, max -> {
assertEquals(max.getValue(), 19.0, 0);
assertTrue(AggregationInspectionHelper.hasValue(max));
}, fieldType);
}

public void testScript() throws IOException {
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.INTEGER);
fieldType.setName("number");
Expand Down

0 comments on commit 9b33165

Please sign in to comment.