From f5a269b029c4a357e257d7ef9b849470e76a2ddf Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 27 Jun 2016 11:21:45 -0400 Subject: [PATCH] Start migration away from aggregation streams We'll migrate to NamedWriteable so we can share code with the rest of the system. So we can work on this in multiple pull requests without breaking Elasticsearch in between the commits this change supports *both* old style `InternalAggregations.stream` serialization and `NamedWriteable` style serialization. As such it creates about a half dozen `// NORELEASE` comments that will have to be removed once the migration is complete. This also introduces a boolean `transportClient` flag to `SearchModule` which is used to skip inappropriate registrations for for the transport client while still registering the things it needs. In this case that means that the `InternalAggregation` subclasses are registered with the `NamedWriteableRegistry` but the `AggregationBuilder` subclasses are not. Finally, this moves aggregation registration from guice configuration time to `SearchModule` construction time. This will make it simpler to work with in the future as we further clean up Elasticsearch's extension points. --- .../client/transport/TransportClient.java | 7 +- .../java/org/elasticsearch/node/Node.java | 2 +- .../elasticsearch/search/SearchModule.java | 48 +++++--- .../aggregations/InternalAggregation.java | 111 ++++++++++++------ .../aggregations/InternalAggregations.java | 23 +++- .../metrics/InternalMetricsAggregation.java | 10 ++ .../InternalNumericMetricsAggregation.java | 22 ++++ .../metrics/avg/AvgAggregationBuilder.java | 8 +- .../aggregations/metrics/avg/InternalAvg.java | 61 ++++------ .../index/query/InnerHitBuilderTests.java | 2 +- .../search/SearchModuleTests.java | 10 +- .../aggregations/AggregatorParsingTests.java | 2 +- .../aggregations/BaseAggregationTestCase.java | 2 +- .../SignificanceHeuristicTests.java | 4 +- .../builder/SearchSourceBuilderTests.java | 2 +- .../highlight/HighlightBuilderTests.java | 2 +- .../rescore/QueryRescoreBuilderTests.java | 2 +- .../search/sort/AbstractSortTestCase.java | 2 +- .../search/sort/SortBuilderTests.java | 2 +- .../AbstractSuggestionBuilderTestCase.java | 2 +- .../messy/tests/TemplateQueryParserTests.java | 2 +- .../test/AbstractQueryTestCase.java | 2 +- .../hamcrest/ElasticsearchAssertions.java | 2 +- 23 files changed, 204 insertions(+), 126 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index c9313fc08c4..eeb9373c435 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -142,12 +142,7 @@ public class TransportClient extends AbstractClient { } modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry)); modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool)); - modules.add(new SearchModule(settings, namedWriteableRegistry) { - @Override - protected void configure() { - // noop - } - }); + modules.add(new SearchModule(settings, namedWriteableRegistry, true)); modules.add(new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(), pluginsService.filterPlugins(ActionPlugin.class))); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index ff095f749c8..fa7f090c096 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -267,7 +267,7 @@ public class Node implements Closeable { ClusterModule clusterModule = new ClusterModule(settings, clusterService); modules.add(clusterModule); modules.add(new IndicesModule(namedWriteableRegistry, pluginsService.filterPlugins(MapperPlugin.class))); - modules.add(new SearchModule(settings, namedWriteableRegistry)); + modules.add(new SearchModule(settings, namedWriteableRegistry, false)); modules.add(new ActionModule(DiscoveryNode.isIngestNode(settings), false, settings, clusterModule.getIndexNameExpressionResolver(), settingsModule.getClusterSettings(), pluginsService.filterPlugins(ActionPlugin.class))); diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 34a90894425..cd9d6f8a3f0 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -94,6 +94,7 @@ import org.elasticsearch.search.action.SearchTransportService; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregatorParsers; +import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.children.InternalChildren; @@ -264,6 +265,7 @@ import java.util.Set; */ public class SearchModule extends AbstractModule { + private final boolean transportClient; private final Highlighters highlighters; private final Suggesters suggesters; private final ParseFieldRegistry> scoreFunctionParserRegistry = new ParseFieldRegistry<>("score_function"); @@ -287,9 +289,10 @@ public class SearchModule extends AbstractModule { // pkg private so tests can mock Class searchServiceImpl = SearchService.class; - public SearchModule(Settings settings, NamedWriteableRegistry namedWriteableRegistry) { + public SearchModule(Settings settings, NamedWriteableRegistry namedWriteableRegistry, boolean transportClient) { this.settings = settings; this.namedWriteableRegistry = namedWriteableRegistry; + this.transportClient = transportClient; suggesters = new Suggesters(namedWriteableRegistry); highlighters = new Highlighters(settings); registerBuiltinScoreFunctionParsers(); @@ -300,6 +303,7 @@ public class SearchModule extends AbstractModule { registerBuiltinSignificanceHeuristics(); registerBuiltinMovingAverageModels(); registerBuiltinSubFetchPhases(); + registerBuiltinAggregations(); } public void registerHighlighter(String key, Highlighter highligher) { @@ -414,15 +418,27 @@ public class SearchModule extends AbstractModule { /** * Register an aggregation. * - * @param reader reads the aggregation builder from a stream + * @param builderReader reads the {@link AggregationBuilder} from a stream + * @param internalReader reads the {@link InternalAggregation} from a stream * @param aggregationParser reads the aggregation builder from XContent * @param aggregationName names by which the aggregation may be parsed. The first name is special because it is the name that the reader * is registered under. */ - public void registerAggregation(Writeable.Reader reader, Aggregator.Parser aggregationParser, - ParseField aggregationName) { + public void registerAggregation(Writeable.Reader builderReader, + Writeable.Reader internalReader, Aggregator.Parser aggregationParser, + ParseField aggregationName) { + if (false == transportClient) { + namedWriteableRegistry.register(AggregationBuilder.class, aggregationName.getPreferredName(), builderReader); + aggregationParserRegistry.register(aggregationParser, aggregationName); + } + namedWriteableRegistry.register(InternalAggregation.class, aggregationName.getPreferredName(), internalReader); + } + + public void registerAggregation(Writeable.Reader builderReader, Aggregator.Parser aggregationParser, + ParseField aggregationName) { + // NORELEASE remove me in favor of the above method + namedWriteableRegistry.register(AggregationBuilder.class, aggregationName.getPreferredName(), builderReader); aggregationParserRegistry.register(aggregationParser, aggregationName); - namedWriteableRegistry.register(AggregationBuilder.class, aggregationName.getPreferredName(), reader); } /** @@ -441,15 +457,21 @@ public class SearchModule extends AbstractModule { @Override protected void configure() { - bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry); - bind(Suggesters.class).toInstance(suggesters); - configureSearch(); - configureAggs(); - configureShapes(); + if (false == transportClient) { + /* + * Nothing is bound for transport client *but* SearchModule is still responsible for settings up the things like the + * NamedWriteableRegistry. + */ + bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry); + bind(Suggesters.class).toInstance(suggesters); + configureSearch(); + configureShapes(); + bind(AggregatorParsers.class).toInstance(aggregatorParsers); + } } - protected void configureAggs() { - registerAggregation(AvgAggregationBuilder::new, new AvgParser(), AvgAggregationBuilder.AGGREGATION_NAME_FIELD); + private void registerBuiltinAggregations() { + registerAggregation(AvgAggregationBuilder::new, InternalAvg::new, new AvgParser(), AvgAggregationBuilder.AGGREGATION_NAME_FIELD); registerAggregation(SumAggregationBuilder::new, new SumParser(), SumAggregationBuilder.AGGREGATION_NAME_FIELD); registerAggregation(MinAggregationBuilder::new, new MinParser(), MinAggregationBuilder.AGGREGATION_NAME_FIELD); registerAggregation(MaxAggregationBuilder::new, new MaxParser(), MaxAggregationBuilder.AGGREGATION_NAME_FIELD); @@ -527,7 +549,6 @@ public class SearchModule extends AbstractModule { BucketSelectorPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); registerPipelineAggregation(SerialDiffPipelineAggregationBuilder::new, SerialDiffPipelineAggregationBuilder::parse, SerialDiffPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); - bind(AggregatorParsers.class).toInstance(aggregatorParsers); } protected void configureSearch() { @@ -679,7 +700,6 @@ public class SearchModule extends AbstractModule { static { // calcs - InternalAvg.registerStreams(); InternalSum.registerStreams(); InternalMin.registerStreams(); InternalMax.registerStreams(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java index b4fab7093f8..b75244ce889 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.aggregations; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -43,8 +43,8 @@ import java.util.Map; /** * An internal implementation of {@link Aggregation}. Serves as a base class for all aggregation implementations. */ -public abstract class InternalAggregation implements Aggregation, ToXContent, Streamable { - +public abstract class InternalAggregation implements Aggregation, ToXContent, Streamable, NamedWriteable { + // NORELEASE remove Streamable /** * The aggregation type that holds all the string types that are associated with an aggregation: @@ -139,15 +139,84 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, St this.metaData = metaData; } + /** + * Read from a stream. + */ + protected InternalAggregation(StreamInput in) throws IOException { + name = in.readString(); + metaData = in.readMap(); + int size = in.readVInt(); + if (size == 0) { + pipelineAggregators = Collections.emptyList(); + } else { + pipelineAggregators = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + BytesReference type = in.readBytesReference(); + PipelineAggregator pipelineAggregator = PipelineAggregatorStreams.stream(type).readResult(in); + pipelineAggregators.add(pipelineAggregator); + } + } + } + + @Override + public final void readFrom(StreamInput in) throws IOException { + try { + getWriteableName(); // Throws UnsupportedOperationException if this aggregation should be read using old style Streams + assert false : "Used reading constructor instead"; + } catch (UnsupportedOperationException e) { + // OK + } + name = in.readString(); + metaData = in.readMap(); + int size = in.readVInt(); + if (size == 0) { + pipelineAggregators = Collections.emptyList(); + } else { + pipelineAggregators = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + BytesReference type = in.readBytesReference(); + PipelineAggregator pipelineAggregator = PipelineAggregatorStreams.stream(type).readResult(in); + pipelineAggregators.add(pipelineAggregator); + } + } + doReadFrom(in); + } + + protected void doReadFrom(StreamInput in) throws IOException { + throw new UnsupportedOperationException("Use reading constructor instead"); // NORELEASE remove when we remove Streamable + } + + @Override + public final void writeTo(StreamOutput out) throws IOException { + out.writeString(name); // NORELEASE remote writing the name - it is automatically handled with writeNamedWriteable + out.writeGenericValue(metaData); + out.writeVInt(pipelineAggregators.size()); + for (PipelineAggregator pipelineAggregator : pipelineAggregators) { + out.writeBytesReference(pipelineAggregator.type().stream()); + pipelineAggregator.writeTo(out); + } + doWriteTo(out); + } + + protected abstract void doWriteTo(StreamOutput out) throws IOException; + @Override public String getName() { return name; } + @Override + public String getWriteableName() { + // NORELEASE remove me when all InternalAggregations override it + throw new UnsupportedOperationException("Override on every class"); + } + /** * @return The {@link Type} of this aggregation */ - public abstract Type type(); + public Type type() { + throw new UnsupportedOperationException("Use getWriteableName instead"); // NORELEASE remove me + } /** * Reduces the given addAggregation to a single one and returns it. In most cases, the assumption will be the all given @@ -214,40 +283,6 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, St public abstract XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException; - @Override - public final void writeTo(StreamOutput out) throws IOException { - out.writeString(name); - out.writeGenericValue(metaData); - out.writeVInt(pipelineAggregators.size()); - for (PipelineAggregator pipelineAggregator : pipelineAggregators) { - out.writeBytesReference(pipelineAggregator.type().stream()); - pipelineAggregator.writeTo(out); - } - doWriteTo(out); - } - - protected abstract void doWriteTo(StreamOutput out) throws IOException; - - @Override - public final void readFrom(StreamInput in) throws IOException { - name = in.readString(); - metaData = in.readMap(); - int size = in.readVInt(); - if (size == 0) { - pipelineAggregators = Collections.emptyList(); - } else { - pipelineAggregators = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - BytesReference type = in.readBytesReference(); - PipelineAggregator pipelineAggregator = PipelineAggregatorStreams.stream(type).readResult(in); - pipelineAggregators.add(pipelineAggregator); - } - } - doReadFrom(in); - } - - protected abstract void doReadFrom(StreamInput in) throws IOException; - /** * Common xcontent fields that are shared among addAggregation */ diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java index 357886a69f6..75223dcc476 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java @@ -205,9 +205,14 @@ public class InternalAggregations implements Aggregations, ToXContent, Streamabl } else { aggregations = new ArrayList<>(size); for (int i = 0; i < size; i++) { - BytesReference type = in.readBytesReference(); - InternalAggregation aggregation = AggregationStreams.stream(type).readResult(in); - aggregations.add(aggregation); + // NORELEASE temporary hack to support old style streams and new style NamedWriteable at the same time + if (in.readBoolean()) { + aggregations.add(in.readNamedWriteable(InternalAggregation.class)); + } else { + BytesReference type = in.readBytesReference(); + InternalAggregation aggregation = AggregationStreams.stream(type).readResult(in); + aggregations.add(aggregation); + } } } } @@ -217,8 +222,16 @@ public class InternalAggregations implements Aggregations, ToXContent, Streamabl out.writeVInt(aggregations.size()); for (Aggregation aggregation : aggregations) { InternalAggregation internal = (InternalAggregation) aggregation; - out.writeBytesReference(internal.type().stream()); - internal.writeTo(out); + // NORELEASE Temporary hack to support old style streams and new style NamedWriteable at the same time + try { + internal.getWriteableName(); // Throws UnsupportedOperationException if we should use old style streams. + out.writeBoolean(true); + out.writeNamedWriteable(internal); + } catch (UnsupportedOperationException e) { + out.writeBoolean(false); + out.writeBytesReference(internal.type().stream()); + internal.writeTo(out); + } } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalMetricsAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalMetricsAggregation.java index c67b7dc6b2f..5c2b1c46f5e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalMetricsAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalMetricsAggregation.java @@ -19,9 +19,11 @@ package org.elasticsearch.search.aggregations.metrics; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -32,4 +34,12 @@ public abstract class InternalMetricsAggregation extends InternalAggregation { protected InternalMetricsAggregation(String name, List pipelineAggregators, Map metaData) { super(name, pipelineAggregators, metaData); } + + /** + * Read from a stream. + */ + protected InternalMetricsAggregation(StreamInput in) throws IOException { + super(in); + } + } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalNumericMetricsAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalNumericMetricsAggregation.java index 02412ba81c6..15c9d7ed59c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalNumericMetricsAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalNumericMetricsAggregation.java @@ -18,9 +18,11 @@ */ package org.elasticsearch.search.aggregations.metrics; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -41,6 +43,13 @@ public abstract class InternalNumericMetricsAggregation extends InternalMetricsA super(name, pipelineAggregators, metaData); } + /** + * Read from a stream. + */ + protected SingleValue(StreamInput in) throws IOException { + super(in); + } + @Override public String getValueAsString() { return format.format(value()); @@ -67,6 +76,13 @@ public abstract class InternalNumericMetricsAggregation extends InternalMetricsA super(name, pipelineAggregators, metaData); } + /** + * Read from a stream. + */ + protected MultiValue(StreamInput in) throws IOException { + super(in); + } + public abstract double value(String name); public String valueAsString(String name) { @@ -91,4 +107,10 @@ public abstract class InternalNumericMetricsAggregation extends InternalMetricsA super(name, pipelineAggregators, metaData); } + /** + * Read from a stream. + */ + protected InternalNumericMetricsAggregation(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregationBuilder.java index ce098177a0b..830ce35fde7 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregationBuilder.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; @@ -36,18 +37,19 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; public class AvgAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly { - public static final String NAME = InternalAvg.TYPE.name(); + public static final String NAME = "avg"; + private final static Type TYPE = new Type(NAME); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public AvgAggregationBuilder(String name) { - super(name, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + super(name, TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } /** * Read from a stream. */ public AvgAggregationBuilder(StreamInput in) throws IOException { - super(in, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + super(in, TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } @Override diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java index bb4260b8189..5f0d54db003 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java @@ -22,7 +22,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.AggregationStreams; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; @@ -31,30 +30,9 @@ import java.io.IOException; import java.util.List; import java.util.Map; -/** -* -*/ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue implements Avg { - - public final static Type TYPE = new Type("avg"); - - public final static AggregationStreams.Stream STREAM = new AggregationStreams.Stream() { - @Override - public InternalAvg readResult(StreamInput in) throws IOException { - InternalAvg result = new InternalAvg(); - result.readFrom(in); - return result; - } - }; - - public static void registerStreams() { - AggregationStreams.registerStream(STREAM, TYPE.stream()); - } - - private double sum; - private long count; - - InternalAvg() {} // for serialization + private final double sum; + private final long count; public InternalAvg(String name, double sum, long count, DocValueFormat format, List pipelineAggregators, Map metaData) { @@ -64,6 +42,23 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i this.format = format; } + /** + * Read from a stream. + */ + public InternalAvg(StreamInput in) throws IOException { + super(in); + format = in.readNamedWriteable(DocValueFormat.class); + sum = in.readDouble(); + count = in.readVLong(); + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeNamedWriteable(format); + out.writeDouble(sum); + out.writeVLong(count); + } + @Override public double value() { return getValue(); @@ -75,8 +70,8 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i } @Override - public Type type() { - return TYPE; + public String getWriteableName() { + return AvgAggregationBuilder.NAME; } @Override @@ -90,20 +85,6 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i return new InternalAvg(getName(), sum, count, format, pipelineAggregators(), getMetaData()); } - @Override - protected void doReadFrom(StreamInput in) throws IOException { - format = in.readNamedWriteable(DocValueFormat.class); - sum = in.readDouble(); - count = in.readVLong(); - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeNamedWriteable(format); - out.writeDouble(sum); - out.writeVLong(count); - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { builder.field(CommonFields.VALUE, count != 0 ? getValue() : null); diff --git a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java index d4ba6ca9062..6460d8505ee 100644 --- a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java @@ -67,7 +67,7 @@ public class InnerHitBuilderTests extends ESTestCase { @BeforeClass public static void init() { namedWriteableRegistry = new NamedWriteableRegistry(); - indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry).getQueryParserRegistry(); + indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry, false).getQueryParserRegistry(); } @AfterClass diff --git a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java index 72873bc0d48..20a557d56a6 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java @@ -47,7 +47,7 @@ import static org.hamcrest.Matchers.notNullValue; public class SearchModuleTests extends ModuleTestCase { public void testDoubleRegister() { - SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry()); + SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry(), false); try { module.registerHighlighter("fvh", new PlainHighlighter()); } catch (IllegalArgumentException e) { @@ -62,7 +62,7 @@ public class SearchModuleTests extends ModuleTestCase { } public void testRegisterSuggester() { - SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry()); + SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry(), false); module.registerSuggester("custom", CustomSuggester.INSTANCE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> module.registerSuggester("custom", CustomSuggester.INSTANCE)); @@ -70,7 +70,7 @@ public class SearchModuleTests extends ModuleTestCase { } public void testRegisterHighlighter() { - SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry()); + SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry(), false); CustomHighlighter customHighlighter = new CustomHighlighter(); module.registerHighlighter("custom", customHighlighter); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, @@ -88,14 +88,14 @@ public class SearchModuleTests extends ModuleTestCase { } public void testRegisterQueryParserDuplicate() { - SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry()); + SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry(), false); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> module .registerQuery(TermQueryBuilder::new, TermQueryBuilder::fromXContent, TermQueryBuilder.QUERY_NAME_FIELD)); assertThat(e.getMessage(), containsString("] already registered for [query][term] while trying to register [org.elasticsearch.")); } public void testRegisteredQueries() throws IOException { - SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry()); + SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry(), false); List allSupportedQueries = new ArrayList<>(); Collections.addAll(allSupportedQueries, NON_DEPRECATED_QUERIES); Collections.addAll(allSupportedQueries, DEPRECATED_QUERIES); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index 1a21069623d..58b4b97db5c 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -119,7 +119,7 @@ public class AggregatorParsingTests extends ESTestCase { protected void configure() { bindMapperExtension(); } - }, new SearchModule(settings, namedWriteableRegistry) { + }, new SearchModule(settings, namedWriteableRegistry, false) { @Override protected void configureSearch() { // Skip me diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index 4e0429fca87..a4103e7ee56 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -151,7 +151,7 @@ public abstract class BaseAggregationTestCase heuristicParserMapper = searchModule.getSignificanceHeuristicParserRegistry(); SearchContext searchContext = new SignificantTermsTestSearchContext(); diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index f3a78b65d78..ac90fabcb07 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -145,7 +145,7 @@ public class SearchSourceBuilderTests extends ESTestCase { bindMapperExtension(); } }, - new SearchModule(settings, namedWriteableRegistry) { + new SearchModule(settings, namedWriteableRegistry, false) { @Override protected void configureSearch() { // Skip me diff --git a/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java b/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java index 9ebbb5b42e0..930a7b220e0 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java @@ -83,7 +83,7 @@ public class HighlightBuilderTests extends ESTestCase { @BeforeClass public static void init() { namedWriteableRegistry = new NamedWriteableRegistry(); - indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry).getQueryParserRegistry(); + indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry, false).getQueryParserRegistry(); } @AfterClass diff --git a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java index f965d3ac5fd..7c3690dcf35 100644 --- a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java @@ -70,7 +70,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { @BeforeClass public static void init() { namedWriteableRegistry = new NamedWriteableRegistry(); - indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry).getQueryParserRegistry(); + indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry, false).getQueryParserRegistry(); } @AfterClass diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index bdd5c76534c..b494fa4d1e6 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -106,7 +106,7 @@ public abstract class AbstractSortTestCase> extends EST }; namedWriteableRegistry = new NamedWriteableRegistry(); - indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry).getQueryParserRegistry(); + indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry, false).getQueryParserRegistry(); } @AfterClass diff --git a/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java index f31158ff34e..54b12216302 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java @@ -52,7 +52,7 @@ public class SortBuilderTests extends ESTestCase { @BeforeClass public static void init() { namedWriteableRegistry = new NamedWriteableRegistry(); - indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry).getQueryParserRegistry(); + indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry, false).getQueryParserRegistry(); } @AfterClass diff --git a/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java b/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java index 1f4030f487c..cd6c34497f7 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java @@ -56,7 +56,7 @@ public abstract class AbstractSuggestionBuilderTestCase> scriptSettings.addAll(pluginsService.getPluginSettings()); scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, pluginsService.getPluginSettingsFilter()); - searchModule = new SearchModule(settings, namedWriteableRegistry) { + searchModule = new SearchModule(settings, namedWriteableRegistry, false) { @Override protected void configureSearch() { // Skip me diff --git a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 51d15e019a4..baad3ef6f04 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -631,7 +631,7 @@ public class ElasticsearchAssertions { registry = ESIntegTestCase.internalCluster().getInstance(NamedWriteableRegistry.class); } else { registry = new NamedWriteableRegistry(); - new SearchModule(Settings.EMPTY, registry); + new SearchModule(Settings.EMPTY, registry, false); } assertVersionSerializable(version, streamable, registry); }