diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java index 1e2e011276d..134ce6c87b3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.core.rollup; import org.elasticsearch.common.ParseField; +import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; @@ -15,6 +16,8 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuil import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class RollupField { // Fields that are used both in core Rollup actions and Rollup plugin @@ -34,6 +37,16 @@ public class RollupField { public static final List SUPPORTED_METRICS = Arrays.asList(MaxAggregationBuilder.NAME, MinAggregationBuilder.NAME, SumAggregationBuilder.NAME, AvgAggregationBuilder.NAME, ValueCountAggregationBuilder.NAME); + // these mapper types are used by the configs (metric, histo, etc) to validate field mappings + public static final List NUMERIC_FIELD_MAPPER_TYPES; + static { + List types = Stream.of(NumberFieldMapper.NumberType.values()) + .map(NumberFieldMapper.NumberType::typeName) + .collect(Collectors.toList()); + types.add("scaled_float"); // have to add manually since scaled_float is in a module + NUMERIC_FIELD_MAPPER_TYPES = types; + } + /** * Format to the appropriate Rollup field name convention * diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfig.java index 2b1511077d9..87de9e16534 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfig.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.composite.HistogramValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; @@ -30,7 +29,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * The configuration object for the histograms in the rollup config @@ -51,10 +49,6 @@ public class HistoGroupConfig implements Writeable, ToXContentFragment { private static final ParseField INTERVAL = new ParseField("interval"); private static final ParseField FIELDS = new ParseField("fields"); - private static final List MAPPER_TYPES = Stream.of(NumberFieldMapper.NumberType.values()) - .map(NumberFieldMapper.NumberType::typeName) - .collect(Collectors.toList()); - private final long interval; private final String[] fields; @@ -126,7 +120,7 @@ public class HistoGroupConfig implements Writeable, ToXContentFragment { Map fieldCaps = fieldCapsResponse.get(field); if (fieldCaps != null && fieldCaps.isEmpty() == false) { fieldCaps.forEach((key, value) -> { - if (MAPPER_TYPES.contains(key)) { + if (RollupField.NUMERIC_FIELD_MAPPER_TYPES.contains(key)) { if (value.isAggregatable() == false) { validationException.addValidationError("The field [" + field + "] must be aggregatable across all indices, " + "but is not."); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java index 67b83646c42..006d8c35c32 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; @@ -32,7 +31,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * The configuration object for the metrics portion of a rollup job config @@ -66,15 +64,6 @@ public class MetricConfig implements Writeable, ToXContentFragment { private static final ParseField AVG = new ParseField("avg"); private static final ParseField VALUE_COUNT = new ParseField("value_count"); - private static final List MAPPER_TYPES; - static { - List types = Stream.of(NumberFieldMapper.NumberType.values()) - .map(NumberFieldMapper.NumberType::typeName) - .collect(Collectors.toList()); - types.add("scaled_float"); // have to add manually since scaled_float is in a module - MAPPER_TYPES = types; - } - public static final ObjectParser PARSER = new ObjectParser<>(NAME, MetricConfig.Builder::new); static { @@ -153,7 +142,7 @@ public class MetricConfig implements Writeable, ToXContentFragment { Map fieldCaps = fieldCapsResponse.get(field); if (fieldCaps != null && fieldCaps.isEmpty() == false) { fieldCaps.forEach((key, value) -> { - if (MAPPER_TYPES.contains(key)) { + if (RollupField.NUMERIC_FIELD_MAPPER_TYPES.contains(key)) { if (value.isAggregatable() == false) { validationException.addValidationError("The field [" + field + "] must be aggregatable across all indices, " + "but is not."); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfigSerializingTests.java index 18a64bc2adf..92e7d8b9643 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistoGroupConfigSerializingTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Collections; @@ -111,7 +112,8 @@ public class HistoGroupConfigSerializingTests extends AbstractSerializingTestCas // Have to mock fieldcaps because the ctor's aren't public... FieldCapabilities fieldCaps = mock(FieldCapabilities.class); when(fieldCaps.isAggregatable()).thenReturn(true); - responseMap.put("my_field", Collections.singletonMap("long", fieldCaps)); + String mappingType = randomFrom(RollupField.NUMERIC_FIELD_MAPPER_TYPES); + responseMap.put("my_field", Collections.singletonMap(mappingType, fieldCaps)); HistoGroupConfig config = new HistoGroupConfig.Builder() .setFields(Collections.singletonList("my_field"))