Fix ignoring missing values in min/max aggregations (#48970)

Fixes the issue when the missing values can be ignored in min/max
due to BKD optimization.

Fixes #48905
This commit is contained in:
Igor Motov 2019-11-12 15:11:43 -05:00
parent 0e1035241d
commit 40776eedaf
2 changed files with 18 additions and 1 deletions

View File

@ -181,7 +181,7 @@ class MinAggregator extends NumericMetricsAggregator.SingleValue {
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;

View File

@ -87,6 +87,7 @@ import java.util.function.Consumer;
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;
@ -232,6 +233,22 @@ public class MaxAggregatorTests extends AggregatorTestCase {
}, 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");