diff --git a/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java b/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java index fffb41911ad..49d2a40baf9 100644 --- a/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.lucene.search.function.ScoreFunction; +import org.elasticsearch.common.xcontent.ContextParser; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryBuilder; @@ -256,7 +257,7 @@ public interface SearchPlugin { /** * Specification for an {@link Aggregation}. */ - class AggregationSpec extends SearchExtensionSpec { + class AggregationSpec extends SearchExtensionSpec> { private final Map> resultReaders = new TreeMap<>(); /** @@ -269,7 +270,8 @@ public interface SearchPlugin { * {@link StreamInput} * @param parser the parser the reads the aggregation builder from xcontent */ - public AggregationSpec(ParseField name, Writeable.Reader reader, Aggregator.Parser parser) { + public AggregationSpec(ParseField name, Writeable.Reader reader, + ContextParser parser) { super(name, reader, parser); } @@ -282,10 +284,41 @@ public interface SearchPlugin { * {@link StreamInput} * @param parser the parser the reads the aggregation builder from xcontent */ - public AggregationSpec(String name, Writeable.Reader reader, Aggregator.Parser parser) { + public AggregationSpec(String name, Writeable.Reader reader, ContextParser parser) { super(name, reader, parser); } + /** + * Specification for an {@link Aggregation}. + * + * @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 reader is registered. So it is the name that the {@link AggregationBuilder} should return + * from {@link NamedWriteable#getWriteableName()}. + * @param reader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a + * {@link StreamInput} + * @param parser the parser the reads the aggregation builder from xcontent + * @deprecated Use the ctor that takes a {@link ContextParser} instead + */ + @Deprecated + public AggregationSpec(ParseField name, Writeable.Reader reader, Aggregator.Parser parser) { + super(name, reader, (p, aggName) -> parser.parse(aggName, p)); + } + + /** + * Specification for an {@link Aggregation}. + * + * @param name the name by which this aggregation might be parsed or deserialized. Make sure that the {@link AggregationBuilder} + * returns this from {@link NamedWriteable#getWriteableName()}. + * @param reader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a + * {@link StreamInput} + * @param parser the parser the reads the aggregation builder from xcontent + * @deprecated Use the ctor that takes a {@link ContextParser} instead + */ + @Deprecated + public AggregationSpec(String name, Writeable.Reader reader, Aggregator.Parser parser) { + super(name, reader, (p, aggName) -> parser.parse(aggName, p)); + } + /** * 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 7fea213de09..0d5de295301 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/server/src/main/java/org/elasticsearch/search/SearchModule.java @@ -452,9 +452,9 @@ public class SearchModule { registerAggregation(new AggregationSpec(GeoCentroidAggregationBuilder.NAME, GeoCentroidAggregationBuilder::new, GeoCentroidAggregationBuilder::parse).addResultReader(InternalGeoCentroid::new)); registerAggregation(new AggregationSpec(ScriptedMetricAggregationBuilder.NAME, ScriptedMetricAggregationBuilder::new, - (name, p) -> ScriptedMetricAggregationBuilder.PARSER.parse(p, name)).addResultReader(InternalScriptedMetric::new)); + ScriptedMetricAggregationBuilder.PARSER).addResultReader(InternalScriptedMetric::new)); registerAggregation((new AggregationSpec(CompositeAggregationBuilder.NAME, CompositeAggregationBuilder::new, - (name, p) -> CompositeAggregationBuilder.PARSER.parse(p, name)).addResultReader(InternalComposite::new))); + CompositeAggregationBuilder.PARSER).addResultReader(InternalComposite::new))); registerFromPlugin(plugins, SearchPlugin::getAggregations, this::registerAggregation); } @@ -462,7 +462,7 @@ public class SearchModule { if (false == transportClient) { namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), (p, c) -> { String name = (String) c; - return spec.getParser().parse(name, p); + return spec.getParser().parse(p, name); })); } namedWriteables.add(