Skip to content

Commit a53e4aa

Browse files
author
Hendrik Muhs
authored
fallback to float if source type is scaled_float for mapping deduction (#51990) (#52006)
fallback to float if source type is scaled_float for mapping deduction of min/max aggregation fixes #51780
1 parent 0460712 commit a53e4aa

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/Aggregations.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public final class Aggregations {
1717
private static final String DYNAMIC = "_dynamic";
1818
// the field mapping should be determined explicitly from the source field mapping if possible.
1919
private static final String SOURCE = "_source";
20+
public static final String FLOAT = "float";
21+
public static final String SCALED_FLOAT = "scaled_float";
22+
public static final String DOUBLE = "double";
23+
public static final String LONG = "long";
24+
public static final String GEO_SHAPE = "geo_shape";
25+
public static final String GEO_POINT = "geo_point";
26+
2027
private Aggregations() {}
2128

2229
/**
@@ -29,14 +36,14 @@ private Aggregations() {}
2936
*
3037
*/
3138
enum AggregationType {
32-
AVG("avg", "double"),
33-
CARDINALITY("cardinality", "long"),
34-
VALUE_COUNT("value_count", "long"),
39+
AVG("avg", DOUBLE),
40+
CARDINALITY("cardinality", LONG),
41+
VALUE_COUNT("value_count", LONG),
3542
MAX("max", SOURCE),
3643
MIN("min", SOURCE),
37-
SUM("sum", "double"),
38-
GEO_CENTROID("geo_centroid", "geo_point"),
39-
GEO_BOUNDS("geo_bounds", "geo_shape"),
44+
SUM("sum", DOUBLE),
45+
GEO_CENTROID("geo_centroid", GEO_POINT),
46+
GEO_BOUNDS("geo_bounds", GEO_SHAPE),
4047
SCRIPTED_METRIC("scripted_metric", DYNAMIC),
4148
WEIGHTED_AVG("weighted_avg", DYNAMIC),
4249
BUCKET_SELECTOR("bucket_selector", DYNAMIC),
@@ -72,6 +79,15 @@ public static boolean isDynamicMapping(String targetMapping) {
7279

7380
public static String resolveTargetMapping(String aggregationType, String sourceType) {
7481
AggregationType agg = AggregationType.valueOf(aggregationType.toUpperCase(Locale.ROOT));
75-
return agg.getTargetMapping().equals(SOURCE) ? sourceType : agg.getTargetMapping();
82+
83+
if (agg.getTargetMapping().equals(SOURCE)) {
84+
// scaled float requires an additional parameter "scaling_factor", which we do not know, therefore we fallback to float
85+
if (sourceType.equals(SCALED_FLOAT)) {
86+
return FLOAT;
87+
}
88+
return sourceType;
89+
}
90+
91+
return agg.getTargetMapping();
7692
}
7793
}

x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationsTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public void testResolveTargetMapping() {
2727
assertEquals("int", Aggregations.resolveTargetMapping("max", "int"));
2828
assertEquals("double", Aggregations.resolveTargetMapping("max", "double"));
2929
assertEquals("half_float", Aggregations.resolveTargetMapping("max", "half_float"));
30+
assertEquals("float", Aggregations.resolveTargetMapping("max", "scaled_float"));
3031

3132
// min
3233
assertEquals("int", Aggregations.resolveTargetMapping("min", "int"));
3334
assertEquals("double", Aggregations.resolveTargetMapping("min", "double"));
3435
assertEquals("half_float", Aggregations.resolveTargetMapping("min", "half_float"));
36+
assertEquals("float", Aggregations.resolveTargetMapping("min", "scaled_float"));
3537

3638
// sum
3739
assertEquals("double", Aggregations.resolveTargetMapping("sum", "double"));

0 commit comments

Comments
 (0)