From 8796cdce4b425a3de5838dbf8a071b262894489f Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 19 Feb 2020 09:20:49 -0500 Subject: [PATCH] Modernize boxplot's parser (backport of #52361) (#52372) Uses a newer way to build `ObjectParser` for in `boxplot` that allows us to drop a mostly ceremonial method. --- .../elasticsearch/xpack/analytics/AnalyticsPlugin.java | 3 +-- .../analytics/boxplot/BoxplotAggregationBuilder.java | 10 ++-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java index adc532f2685..8ea6218faa5 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java @@ -16,7 +16,6 @@ import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.MapperPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SearchPlugin; -import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.xpack.analytics.action.TransportAnalyticsStatsAction; import org.elasticsearch.xpack.analytics.boxplot.BoxplotAggregationBuilder; import org.elasticsearch.xpack.analytics.boxplot.InternalBoxplot; @@ -74,7 +73,7 @@ public class AnalyticsPlugin extends Plugin implements SearchPlugin, ActionPlugi new AggregationSpec( BoxplotAggregationBuilder.NAME, BoxplotAggregationBuilder::new, - (ContextParser) (p, c) -> BoxplotAggregationBuilder.parse(c, p)) + BoxplotAggregationBuilder.PARSER) .addResultReader(InternalBoxplot::new), new AggregationSpec( TopMetricsAggregationBuilder.NAME, diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregationBuilder.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregationBuilder.java index 0972cdf7d53..1e090ca2179 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregationBuilder.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregationBuilder.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -33,18 +32,13 @@ public class BoxplotAggregationBuilder extends ValuesSourceAggregationBuilder.Le BoxplotAggregationBuilder> { public static final String NAME = "boxplot"; - private static final ObjectParser PARSER; - + public static final ObjectParser PARSER = + ObjectParser.fromBuilder(NAME, BoxplotAggregationBuilder::new); static { - PARSER = new ObjectParser<>(BoxplotAggregationBuilder.NAME); ValuesSourceParserHelper.declareAnyFields(PARSER, true, true); PARSER.declareDouble(BoxplotAggregationBuilder::compression, COMPRESSION_FIELD); } - public static AggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException { - return PARSER.parse(parser, new BoxplotAggregationBuilder(aggregationName), null); - } - private double compression = 100.0; public BoxplotAggregationBuilder(String name) {