diff --git a/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java b/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java index 49d2a40baf9..fe5c65d6704 100644 --- a/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java @@ -346,7 +346,8 @@ public interface SearchPlugin { /** * Specification for a {@link PipelineAggregator}. */ - class PipelineAggregationSpec extends SearchExtensionSpec { + class PipelineAggregationSpec extends SearchExtensionSpec> { private final Map> resultReaders = new TreeMap<>(); private final Writeable.Reader aggregatorReader; @@ -364,7 +365,7 @@ public interface SearchPlugin { public PipelineAggregationSpec(ParseField name, Writeable.Reader builderReader, Writeable.Reader aggregatorReader, - PipelineAggregator.Parser parser) { + ContextParser parser) { super(name, builderReader, parser); this.aggregatorReader = aggregatorReader; } @@ -383,11 +384,52 @@ public interface SearchPlugin { public PipelineAggregationSpec(String name, Writeable.Reader builderReader, Writeable.Reader aggregatorReader, - PipelineAggregator.Parser parser) { + ContextParser parser) { super(name, builderReader, parser); this.aggregatorReader = aggregatorReader; } + /** + * Specification of a {@link PipelineAggregator}. + * + * @param name holds the names by which this aggregation might be parsed. The {@link ParseField#getPreferredName()} is special as it + * is the name by under which the readers are registered. So it is the name that the {@link PipelineAggregationBuilder} and + * {@link PipelineAggregator} should return from {@link NamedWriteable#getWriteableName()}. + * @param builderReader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a + * {@link StreamInput} + * @param aggregatorReader reads the {@link PipelineAggregator} from a stream + * @param parser reads the aggregation builder from XContent + * @deprecated prefer the ctor that takes a {@link ContextParser} + */ + @Deprecated + public PipelineAggregationSpec(ParseField name, + Writeable.Reader builderReader, + Writeable.Reader aggregatorReader, + PipelineAggregator.Parser parser) { + super(name, builderReader, (p, n) -> parser.parse(n, p)); + this.aggregatorReader = aggregatorReader; + } + + /** + * Specification of a {@link PipelineAggregator}. + * + * @param name name by which this aggregation might be parsed or deserialized. Make sure it is the name that the + * {@link PipelineAggregationBuilder} and {@link PipelineAggregator} should return from + * {@link NamedWriteable#getWriteableName()}. + * @param builderReader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a + * {@link StreamInput} + * @param aggregatorReader reads the {@link PipelineAggregator} from a stream + * @deprecated prefer the ctor that takes a {@link ContextParser} + */ + @Deprecated + public PipelineAggregationSpec(String name, + Writeable.Reader builderReader, + Writeable.Reader aggregatorReader, + PipelineAggregator.Parser parser) { + super(name, builderReader, (p, n) -> parser.parse(n, p)); + this.aggregatorReader = aggregatorReader; + } + /** * Add a reader for the shard level results of the aggregation with {@linkplain #getName()}'s {@link ParseField#getPreferredName()} * as the {@link NamedWriteable#getWriteableName()}. diff --git a/server/src/main/java/org/elasticsearch/search/SearchModule.java b/server/src/main/java/org/elasticsearch/search/SearchModule.java index c26c061d781..14d0690a6c1 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/server/src/main/java/org/elasticsearch/search/SearchModule.java @@ -531,8 +531,9 @@ public class SearchModule { MovAvgPipelineAggregationBuilder.NAME, MovAvgPipelineAggregationBuilder::new, MovAvgPipelineAggregator::new, - (n, c) -> MovAvgPipelineAggregationBuilder.parse(movingAverageModelParserRegistry, n, c)) - /* Uses InternalHistogram for buckets */); + (XContentParser parser, String name) -> + MovAvgPipelineAggregationBuilder.parse(movingAverageModelParserRegistry, name, parser) + )/* Uses InternalHistogram for buckets */); registerPipelineAggregation(new PipelineAggregationSpec( CumulativeSumPipelineAggregationBuilder.NAME, CumulativeSumPipelineAggregationBuilder::new, @@ -542,7 +543,7 @@ public class SearchModule { BucketScriptPipelineAggregationBuilder.NAME, BucketScriptPipelineAggregationBuilder::new, BucketScriptPipelineAggregator::new, - (name, p) -> BucketScriptPipelineAggregationBuilder.PARSER.parse(p, name))); + BucketScriptPipelineAggregationBuilder.PARSER)); registerPipelineAggregation(new PipelineAggregationSpec( BucketSelectorPipelineAggregationBuilder.NAME, BucketSelectorPipelineAggregationBuilder::new, @@ -562,17 +563,15 @@ public class SearchModule { MovFnPipelineAggregationBuilder.NAME, MovFnPipelineAggregationBuilder::new, MovFnPipelineAggregator::new, - (name, p) -> MovFnPipelineAggregationBuilder.PARSER.parse(p, name))); + MovFnPipelineAggregationBuilder.PARSER)); registerFromPlugin(plugins, SearchPlugin::getPipelineAggregations, this::registerPipelineAggregation); } private void registerPipelineAggregation(PipelineAggregationSpec spec) { if (false == transportClient) { - namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), (p, c) -> { - String name = (String) c; - return spec.getParser().parse(name, p); - })); + namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), + (p, c) -> spec.getParser().parse(p, (String) c))); } namedWriteables.add( new NamedWriteableRegistry.Entry(PipelineAggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader())); 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 8ea6218faa5..e14e45b4cd4 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 @@ -59,7 +59,7 @@ public class AnalyticsPlugin extends Plugin implements SearchPlugin, ActionPlugi CumulativeCardinalityPipelineAggregationBuilder.NAME, CumulativeCardinalityPipelineAggregationBuilder::new, CumulativeCardinalityPipelineAggregator::new, - (name, p) -> CumulativeCardinalityPipelineAggregationBuilder.PARSER.parse(p, name)) + CumulativeCardinalityPipelineAggregationBuilder.PARSER) ); }