From 9811caa00356d11f1580a7554fda0d9c3cf4af05 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Thu, 6 Feb 2020 17:26:43 +0100 Subject: [PATCH] fallback to float if source type is scaled_float for mapping deduction (#51990) fallback to float if source type is scaled_float for mapping deduction of min/max aggregation fixes #51780 --- .../transforms/pivot/Aggregations.java | 30 ++++++++++++++----- .../transforms/pivot/AggregationsTests.java | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/Aggregations.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/Aggregations.java index effa3eb1e0e5f..8ebff44b9dfbe 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/Aggregations.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/Aggregations.java @@ -17,6 +17,13 @@ public final class Aggregations { private static final String DYNAMIC = "_dynamic"; // the field mapping should be determined explicitly from the source field mapping if possible. private static final String SOURCE = "_source"; + public static final String FLOAT = "float"; + public static final String SCALED_FLOAT = "scaled_float"; + public static final String DOUBLE = "double"; + public static final String LONG = "long"; + public static final String GEO_SHAPE = "geo_shape"; + public static final String GEO_POINT = "geo_point"; + private Aggregations() {} /** @@ -29,14 +36,14 @@ private Aggregations() {} * */ enum AggregationType { - AVG("avg", "double"), - CARDINALITY("cardinality", "long"), - VALUE_COUNT("value_count", "long"), + AVG("avg", DOUBLE), + CARDINALITY("cardinality", LONG), + VALUE_COUNT("value_count", LONG), MAX("max", SOURCE), MIN("min", SOURCE), - SUM("sum", "double"), - GEO_CENTROID("geo_centroid", "geo_point"), - GEO_BOUNDS("geo_bounds", "geo_shape"), + SUM("sum", DOUBLE), + GEO_CENTROID("geo_centroid", GEO_POINT), + GEO_BOUNDS("geo_bounds", GEO_SHAPE), SCRIPTED_METRIC("scripted_metric", DYNAMIC), WEIGHTED_AVG("weighted_avg", DYNAMIC), BUCKET_SELECTOR("bucket_selector", DYNAMIC), @@ -72,6 +79,15 @@ public static boolean isDynamicMapping(String targetMapping) { public static String resolveTargetMapping(String aggregationType, String sourceType) { AggregationType agg = AggregationType.valueOf(aggregationType.toUpperCase(Locale.ROOT)); - return agg.getTargetMapping().equals(SOURCE) ? sourceType : agg.getTargetMapping(); + + if (agg.getTargetMapping().equals(SOURCE)) { + // scaled float requires an additional parameter "scaling_factor", which we do not know, therefore we fallback to float + if (sourceType.equals(SCALED_FLOAT)) { + return FLOAT; + } + return sourceType; + } + + return agg.getTargetMapping(); } } diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationsTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationsTests.java index ee66d20859f4f..32cfda7e17fd5 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationsTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationsTests.java @@ -27,11 +27,13 @@ public void testResolveTargetMapping() { assertEquals("int", Aggregations.resolveTargetMapping("max", "int")); assertEquals("double", Aggregations.resolveTargetMapping("max", "double")); assertEquals("half_float", Aggregations.resolveTargetMapping("max", "half_float")); + assertEquals("float", Aggregations.resolveTargetMapping("max", "scaled_float")); // min assertEquals("int", Aggregations.resolveTargetMapping("min", "int")); assertEquals("double", Aggregations.resolveTargetMapping("min", "double")); assertEquals("half_float", Aggregations.resolveTargetMapping("min", "half_float")); + assertEquals("float", Aggregations.resolveTargetMapping("min", "scaled_float")); // sum assertEquals("double", Aggregations.resolveTargetMapping("sum", "double"));