Merge pull request #12913 from xuzha/xu-exception
Validate class before cast.
This commit is contained in:
commit
1f2345db34
|
@ -156,6 +156,12 @@ public class AggregationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValuesSource.Numeric numericField(ValuesSourceConfig<?> config) throws IOException {
|
private ValuesSource.Numeric numericField(ValuesSourceConfig<?> config) throws IOException {
|
||||||
|
|
||||||
|
if (!(config.fieldContext.indexFieldData() instanceof IndexNumericFieldData)) {
|
||||||
|
throw new IllegalArgumentException("Expected numeric type on field [" + config.fieldContext.field() +
|
||||||
|
"], but got [" + config.fieldContext.fieldType().typeName() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData) config.fieldContext.indexFieldData());
|
ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData) config.fieldContext.indexFieldData());
|
||||||
if (config.script != null) {
|
if (config.script != null) {
|
||||||
dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script);
|
dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script);
|
||||||
|
@ -184,6 +190,12 @@ public class AggregationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValuesSource.GeoPoint geoPointField(ValuesSourceConfig<?> config) throws IOException {
|
private ValuesSource.GeoPoint geoPointField(ValuesSourceConfig<?> config) throws IOException {
|
||||||
|
|
||||||
|
if (!(config.fieldContext.indexFieldData() instanceof IndexGeoPointFieldData)) {
|
||||||
|
throw new IllegalArgumentException("Expected geo_point type on field [" + config.fieldContext.field() +
|
||||||
|
"], but got [" + config.fieldContext.fieldType().typeName() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) config.fieldContext.indexFieldData());
|
return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) config.fieldContext.indexFieldData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue