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
This commit is contained in:
parent
884d4904d4
commit
03fb5cdaae
|
@ -25,6 +25,13 @@ public final class Aggregations {
|
||||||
// the field mapping should be determined explicitly from the source field mapping if possible.
|
// the field mapping should be determined explicitly from the source field mapping if possible.
|
||||||
private static final String SOURCE = "_source";
|
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() {}
|
private Aggregations() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,19 +44,19 @@ public final class Aggregations {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
enum AggregationType {
|
enum AggregationType {
|
||||||
AVG("avg", "double"),
|
AVG("avg", DOUBLE),
|
||||||
CARDINALITY("cardinality", "long"),
|
CARDINALITY("cardinality", LONG),
|
||||||
VALUE_COUNT("value_count", "long"),
|
VALUE_COUNT("value_count", LONG),
|
||||||
MAX("max", SOURCE),
|
MAX("max", SOURCE),
|
||||||
MIN("min", SOURCE),
|
MIN("min", SOURCE),
|
||||||
SUM("sum", "double"),
|
SUM("sum", DOUBLE),
|
||||||
GEO_CENTROID("geo_centroid", "geo_point"),
|
GEO_CENTROID("geo_centroid", GEO_POINT),
|
||||||
GEO_BOUNDS("geo_bounds", "geo_shape"),
|
GEO_BOUNDS("geo_bounds", GEO_SHAPE),
|
||||||
SCRIPTED_METRIC("scripted_metric", DYNAMIC),
|
SCRIPTED_METRIC("scripted_metric", DYNAMIC),
|
||||||
WEIGHTED_AVG("weighted_avg", DYNAMIC),
|
WEIGHTED_AVG("weighted_avg", DYNAMIC),
|
||||||
BUCKET_SELECTOR("bucket_selector", DYNAMIC),
|
BUCKET_SELECTOR("bucket_selector", DYNAMIC),
|
||||||
BUCKET_SCRIPT("bucket_script", DYNAMIC),
|
BUCKET_SCRIPT("bucket_script", DYNAMIC),
|
||||||
PERCENTILES("percentiles", "double");
|
PERCENTILES("percentiles", DOUBLE);
|
||||||
|
|
||||||
private final String aggregationType;
|
private final String aggregationType;
|
||||||
private final String targetMapping;
|
private final String targetMapping;
|
||||||
|
@ -82,7 +89,16 @@ public final class Aggregations {
|
||||||
|
|
||||||
public static String resolveTargetMapping(String aggregationType, String sourceType) {
|
public static String resolveTargetMapping(String aggregationType, String sourceType) {
|
||||||
AggregationType agg = AggregationType.valueOf(aggregationType.toUpperCase(Locale.ROOT));
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> getAggregationOutputTypes(AggregationBuilder agg) {
|
public static Map<String, String> getAggregationOutputTypes(AggregationBuilder agg) {
|
||||||
|
|
|
@ -27,11 +27,13 @@ public class AggregationsTests extends ESTestCase {
|
||||||
assertEquals("int", Aggregations.resolveTargetMapping("max", "int"));
|
assertEquals("int", Aggregations.resolveTargetMapping("max", "int"));
|
||||||
assertEquals("double", Aggregations.resolveTargetMapping("max", "double"));
|
assertEquals("double", Aggregations.resolveTargetMapping("max", "double"));
|
||||||
assertEquals("half_float", Aggregations.resolveTargetMapping("max", "half_float"));
|
assertEquals("half_float", Aggregations.resolveTargetMapping("max", "half_float"));
|
||||||
|
assertEquals("float", Aggregations.resolveTargetMapping("max", "scaled_float"));
|
||||||
|
|
||||||
// min
|
// min
|
||||||
assertEquals("int", Aggregations.resolveTargetMapping("min", "int"));
|
assertEquals("int", Aggregations.resolveTargetMapping("min", "int"));
|
||||||
assertEquals("double", Aggregations.resolveTargetMapping("min", "double"));
|
assertEquals("double", Aggregations.resolveTargetMapping("min", "double"));
|
||||||
assertEquals("half_float", Aggregations.resolveTargetMapping("min", "half_float"));
|
assertEquals("half_float", Aggregations.resolveTargetMapping("min", "half_float"));
|
||||||
|
assertEquals("float", Aggregations.resolveTargetMapping("min", "scaled_float"));
|
||||||
|
|
||||||
// sum
|
// sum
|
||||||
assertEquals("double", Aggregations.resolveTargetMapping("sum", "double"));
|
assertEquals("double", Aggregations.resolveTargetMapping("sum", "double"));
|
||||||
|
|
Loading…
Reference in New Issue