diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 443e232bcd9..4efe49d9c23 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -193,21 +193,21 @@ import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketParser; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketParser; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketParser; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator; @@ -502,15 +502,20 @@ public class SearchModule extends AbstractModule { registerPipelineAggregation(DerivativePipelineAggregatorBuilder::new, DerivativePipelineAggregatorBuilder::parse, DerivativePipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineParser(new MaxBucketParser()); - registerPipelineParser(new MinBucketParser()); - registerPipelineParser(new AvgBucketParser()); - registerPipelineParser(new SumBucketParser()); + registerPipelineAggregation(MaxBucketPipelineAggregatorBuilder::new, MaxBucketPipelineAggregatorBuilder.PARSER, + MaxBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(MinBucketPipelineAggregatorBuilder::new, MinBucketPipelineAggregatorBuilder.PARSER, + MinBucketPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME); + registerPipelineAggregation(AvgBucketPipelineAggregatorBuilder::new, AvgBucketPipelineAggregatorBuilder.PARSER, + AvgBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(SumBucketPipelineAggregatorBuilder::new, SumBucketPipelineAggregatorBuilder.PARSER, + SumBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); registerPipelineAggregation(StatsBucketPipelineAggregatorBuilder::new, StatsBucketPipelineAggregatorBuilder.PARSER, StatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(), ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineParser(new PercentilesBucketParser()); + registerPipelineAggregation(PercentilesBucketPipelineAggregatorBuilder::new, PercentilesBucketPipelineAggregatorBuilder.PARSER, + PercentilesBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); registerPipelineAggregation(MovAvgPipelineAggregatorBuilder::new, (n, c) -> MovAvgPipelineAggregatorBuilder.parse(movAvgModelParserMapper, n, c), MovAvgPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java deleted file mode 100644 index f352f7ab289..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; - -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; - -import java.util.Map; - -public class AvgBucketParser extends BucketMetricsParser { - @Override - public String type() { - return AvgBucketPipelineAggregator.TYPE.name(); - } - - @Override - protected AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, - Map unparsedParams) { - return new AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); - } - - @Override - public AvgBucketPipelineAggregatorBuilder getFactoryPrototype() { - return AvgBucketPipelineAggregatorBuilder.PROTOTYPE; - } -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java index 1d62dfe10d7..49ea65d3310 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java @@ -19,12 +19,14 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; +import org.elasticsearch.common.ParseField; 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.AggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import java.io.IOException; @@ -32,15 +34,28 @@ import java.util.List; import java.util.Map; public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { - - static final AvgBucketPipelineAggregatorBuilder PROTOTYPE = new AvgBucketPipelineAggregatorBuilder("", ""); + public static final String NAME = AvgBucketPipelineAggregator.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public AvgBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); + super(name, AvgBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } - private AvgBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, AvgBucketPipelineAggregator.TYPE.name(), bucketsPaths); + /** + * Read from a stream. + */ + public AvgBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + super(in, NAME); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; } @Override @@ -62,15 +77,13 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg return builder; } - @Override - protected AvgBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - return new AvgBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } + public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { + @Override + protected AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + String bucketsPath, Map unparsedParams) { + return new AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + } + }; @Override protected int innerHashCode() { @@ -82,4 +95,8 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg return true; } + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java deleted file mode 100644 index 51393e7e082..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; - -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; - -import java.util.Map; - -public class MaxBucketParser extends BucketMetricsParser { - - @Override - public String type() { - return MaxBucketPipelineAggregator.TYPE.name(); - } - - @Override - protected MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, - Map unparsedParams) { - return new MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); - } - - @Override - public MaxBucketPipelineAggregatorBuilder getFactoryPrototype() { - return MaxBucketPipelineAggregatorBuilder.PROTOTYPE; - } - -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java index ea9e3efb8fb..acd587b5026 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java @@ -19,29 +19,43 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; +import org.elasticsearch.common.ParseField; 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.AggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class MaxBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final MaxBucketPipelineAggregatorBuilder PROTOTYPE = new MaxBucketPipelineAggregatorBuilder("", ""); +public class MaxBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { + public static final String NAME = MaxBucketPipelineAggregator.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public MaxBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); + super(name, MaxBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } - private MaxBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, MaxBucketPipelineAggregator.TYPE.name(), bucketsPaths); + /** + * Read from a stream. + */ + public MaxBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + super(in, NAME); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; } @Override @@ -63,16 +77,13 @@ public class MaxBucketPipelineAggregatorBuilder return builder; } - @Override - protected MaxBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new MaxBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } + public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { + @Override + protected MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + String bucketsPath, Map unparsedParams) { + return new MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + } + }; @Override protected int innerHashCode() { @@ -84,4 +95,8 @@ public class MaxBucketPipelineAggregatorBuilder return true; } + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java deleted file mode 100644 index ea7c2284857..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; - -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; - -import java.util.Map; - -public class MinBucketParser extends BucketMetricsParser { - - @Override - public String type() { - return MinBucketPipelineAggregator.TYPE.name(); - } - - @Override - protected MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, - Map unparsedParams) { - return new MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); - } - - @Override - public MinBucketPipelineAggregatorBuilder getFactoryPrototype() { - return MinBucketPipelineAggregatorBuilder.PROTOTYPE; - } - -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java index 50e5d978f26..9b5ff99f8be 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java @@ -19,29 +19,43 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; +import org.elasticsearch.common.ParseField; 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.AggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class MinBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final MinBucketPipelineAggregatorBuilder PROTOTYPE = new MinBucketPipelineAggregatorBuilder("", ""); +public class MinBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { + public static final String NAME = MinBucketPipelineAggregator.TYPE.name(); + public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME); public MinBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); + super(name, MinBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } - private MinBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, MinBucketPipelineAggregator.TYPE.name(), bucketsPaths); + /** + * Read from a stream. + */ + public MinBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + super(in, NAME); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; } @Override @@ -63,16 +77,13 @@ public class MinBucketPipelineAggregatorBuilder return builder; } - @Override - protected MinBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new MinBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } + public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { + @Override + protected MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + String bucketsPath, Map unparsedParams) { + return new MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + } + }; @Override protected int innerHashCode() { @@ -84,4 +95,8 @@ public class MinBucketPipelineAggregatorBuilder return true; } + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java deleted file mode 100644 index b1969afb558..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; - -import java.text.ParseException; -import java.util.List; -import java.util.Map; - - -public class PercentilesBucketParser extends BucketMetricsParser { - - public static final ParseField PERCENTS = new ParseField("percents"); - - @Override - public String type() { - return PercentilesBucketPipelineAggregator.TYPE.name(); - } - - @Override - protected PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, - String bucketsPath, Map unparsedParams) throws ParseException { - - double[] percents = null; - int counter = 0; - Object percentParam = unparsedParams.get(PERCENTS.getPreferredName()); - - if (percentParam != null) { - if (percentParam instanceof List) { - percents = new double[((List) percentParam).size()]; - for (Object p : (List) percentParam) { - if (p instanceof Double) { - percents[counter] = (Double) p; - counter += 1; - } else { - throw new ParseException("Parameter [" + PERCENTS.getPreferredName() + "] must be an array of doubles, type `" - + percentParam.getClass().getSimpleName() + "` provided instead", 0); - } - } - unparsedParams.remove(PERCENTS.getPreferredName()); - } else { - throw new ParseException("Parameter [" + PERCENTS.getPreferredName() + "] must be an array of doubles, type `" - + percentParam.getClass().getSimpleName() + "` provided instead", 0); - } - } - - PercentilesBucketPipelineAggregatorBuilder factory = new - PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); - if (percents != null) { - factory.percents(percents); - } - return factory; - } - - @Override - public PercentilesBucketPipelineAggregatorBuilder getFactoryPrototype() { - return PercentilesBucketPipelineAggregatorBuilder.PROTOTYPE; - } -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java index 5f2d279a5f0..9c6faa0dd99 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java @@ -19,15 +19,18 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; +import org.elasticsearch.common.ParseField; 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.AggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import java.io.IOException; +import java.text.ParseException; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -35,17 +38,34 @@ import java.util.Objects; public class PercentilesBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { + public static final String NAME = PercentilesBucketPipelineAggregator.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - static final PercentilesBucketPipelineAggregatorBuilder PROTOTYPE = new PercentilesBucketPipelineAggregatorBuilder("", ""); + private static final ParseField PERCENTS_FIELD = new ParseField("percents"); private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 }; public PercentilesBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); + super(name, PercentilesBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } - private PercentilesBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, PercentilesBucketPipelineAggregator.TYPE.name(), bucketsPaths); + /** + * Read from a stream. + */ + public PercentilesBucketPipelineAggregatorBuilder(StreamInput in) + throws IOException { + super(in, NAME); + percents = in.readDoubleArray(); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDoubleArray(percents); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; } /** @@ -64,7 +84,7 @@ public class PercentilesBucketPipelineAggregatorBuilder } for (Double p : percents) { if (p == null || p < 0.0 || p > 100.0) { - throw new IllegalArgumentException(PercentilesBucketParser.PERCENTS.getPreferredName() + throw new IllegalArgumentException(PERCENTS_FIELD.getPreferredName() + " must only contain non-null doubles from 0.0-100.0 inclusive"); } } @@ -87,7 +107,7 @@ public class PercentilesBucketPipelineAggregatorBuilder for (Double p : percents) { if (p == null || p < 0.0 || p > 100.0) { - throw new IllegalStateException(PercentilesBucketParser.PERCENTS.getPreferredName() + throw new IllegalStateException(PERCENTS_FIELD.getPreferredName() + " must only contain non-null doubles from 0.0-100.0 inclusive"); } } @@ -96,23 +116,48 @@ public class PercentilesBucketPipelineAggregatorBuilder @Override protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { if (percents != null) { - builder.field(PercentilesBucketParser.PERCENTS.getPreferredName(), percents); + builder.field(PERCENTS_FIELD.getPreferredName(), percents); } return builder; } - @Override - protected PercentilesBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - PercentilesBucketPipelineAggregatorBuilder factory = new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPaths); - factory.percents = in.readDoubleArray(); - return factory; - } + public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { + @Override + protected PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + String bucketsPath, Map unparsedParams) throws ParseException { + double[] percents = null; + int counter = 0; + Object percentParam = unparsedParams.get(PERCENTS_FIELD.getPreferredName()); - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDoubleArray(percents); - } + if (percentParam != null) { + if (percentParam instanceof List) { + percents = new double[((List) percentParam).size()]; + for (Object p : (List) percentParam) { + if (p instanceof Double) { + percents[counter] = (Double) p; + counter += 1; + } else { + throw new ParseException( + "Parameter [" + PERCENTS_FIELD.getPreferredName() + "] must be an array of doubles, type `" + + percentParam.getClass().getSimpleName() + "` provided instead", + 0); + } + } + unparsedParams.remove(PERCENTS_FIELD.getPreferredName()); + } else { + throw new ParseException("Parameter [" + PERCENTS_FIELD.getPreferredName() + "] must be an array of doubles, type `" + + percentParam.getClass().getSimpleName() + "` provided instead", 0); + } + } + + PercentilesBucketPipelineAggregatorBuilder factory = new + PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + if (percents != null) { + factory.percents(percents); + } + return factory; + } + }; @Override protected int innerHashCode() { @@ -125,4 +170,8 @@ public class PercentilesBucketPipelineAggregatorBuilder return Objects.deepEquals(percents, other.percents); } + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java deleted file mode 100644 index c4a17cd084d..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; - -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; - -import java.util.Map; - -public class SumBucketParser extends BucketMetricsParser { - @Override - public String type() { - return SumBucketPipelineAggregator.TYPE.name(); - } - - @Override - protected SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, - Map unparsedParams) { - return new SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); - } - - @Override - public SumBucketPipelineAggregatorBuilder getFactoryPrototype() { - return SumBucketPipelineAggregatorBuilder.PROTOTYPE; - } -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java index 25a1ebe6f84..d322b25884c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java @@ -19,29 +19,43 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; +import org.elasticsearch.common.ParseField; 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.AggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class SumBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final SumBucketPipelineAggregatorBuilder PROTOTYPE = new SumBucketPipelineAggregatorBuilder("", ""); +public class SumBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { + public static final String NAME = SumBucketPipelineAggregator.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public SumBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); + super(name, SumBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } - private SumBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, SumBucketPipelineAggregator.TYPE.name(), bucketsPaths); + /** + * Read from a stream. + */ + public SumBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + super(in, NAME); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; } @Override @@ -63,16 +77,13 @@ public class SumBucketPipelineAggregatorBuilder return builder; } - @Override - protected SumBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new SumBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } + public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { + @Override + protected SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + String bucketsPath, Map unparsedParams) { + return new SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + } + }; @Override protected int innerHashCode() { @@ -84,4 +95,8 @@ public class SumBucketPipelineAggregatorBuilder return true; } + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file