-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactor Metric aggregations #4332
Description
As part of #4331, it looks like not all IMetricAggregation implementations support scripting i.e. the Script property
| IScript Script { get; set; } |
Going through the aggregation builder types in Elasticsearch, whether an aggregation supports scripting, formatting, etc. is controlled by declaring the supported fields on the parser. For example, for MinAggregationBuilder
public class MinAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, MinAggregationBuilder> {
public static final String NAME = "min";
private static final ObjectParser<MinAggregationBuilder, Void> PARSER;
static {
PARSER = new ObjectParser<>(AvgAggregationBuilder.NAME);
ValuesSourceParserHelper.declareNumericFields(PARSER, true, true, false); <---
}
...where the bool values are scriptable, formattable and timezoneAware, respectively.
Only the IMetricAggregation that support scripting should allow a Script property to be set. Going through the 7.x Java source, this is the support found
| agg name | scriptable | formattable |
|---|---|---|
| avg | ✔️ | ✔️ |
| cardinality | ✔️ | |
| extended_stats | ✔️ | ✔️ |
| geo_centroid | ✔️ | |
| max | ✔️ | ✔️ |
| median_absolute_derivation | ✔️ | ✔️ |
| min | ✔️ | ✔️ |
| percentile_ranks | ✔️ | ✔️ |
| percentiles | ✔️ | ✔️ |
| stats | ✔️ | ✔️ |
| sum | ✔️ | ✔️ |
| value_count | ✔️ | ✔️ |
(timezone aware is not a column because it doesn't look to apply to metric aggs)
(metric aggregations omitted from the list do not support either script or format)
Possible implementation
Derive an IScriptableMetricAggregation from IMetricAggregation, and IFormattableMetricAggregation from IScriptableMetricAggregation
public interface IMetricAggregation : IAggregation
{
Field Field { get; set; }
[DataMember(Name ="missing")]
object Missing { get; set; }
}
public interface IScriptableMetricAggregation : IMetricAggregation
{
[DataMember(Name ="script")]
IScript Script { get; set; }
}
public interface IFormattableMetricAggregation : IScriptableMetricAggregation
{
[DataMember(Name ="format")]
stringFormat { get; set; }
}NOTE: Missing should also be changed to object