|
@@ -19,26 +19,27 @@
|
|
|
|
|
|
package org.elasticsearch.search.aggregations.metrics.stats.extended;
|
|
|
|
|
|
+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.AggregatorFactories.Builder;
|
|
|
+import org.elasticsearch.search.aggregations.AggregatorFactory;
|
|
|
import org.elasticsearch.search.aggregations.support.AggregationContext;
|
|
|
import org.elasticsearch.search.aggregations.support.ValueType;
|
|
|
import org.elasticsearch.search.aggregations.support.ValuesSource;
|
|
|
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
|
|
|
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
|
|
|
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
|
|
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
|
|
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
public class ExtendedStatsAggregatorBuilder
|
|
|
extends ValuesSourceAggregatorBuilder.LeafOnly<ValuesSource.Numeric, ExtendedStatsAggregatorBuilder> {
|
|
|
-
|
|
|
- static final ExtendedStatsAggregatorBuilder PROTOTYPE = new ExtendedStatsAggregatorBuilder("");
|
|
|
+ public static final String NAME = InternalExtendedStats.TYPE.name();
|
|
|
+ public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
|
|
|
|
|
|
private double sigma = 2.0;
|
|
|
|
|
@@ -46,6 +47,24 @@ public class ExtendedStatsAggregatorBuilder
|
|
|
super(name, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Read from a stream.
|
|
|
+ */
|
|
|
+ public ExtendedStatsAggregatorBuilder(StreamInput in) throws IOException {
|
|
|
+ super(in, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
|
|
|
+ sigma = in.readDouble();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void innerWriteTo(StreamOutput out) throws IOException {
|
|
|
+ out.writeDouble(sigma);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean usesNewStyleSerialization() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
public ExtendedStatsAggregatorBuilder sigma(double sigma) {
|
|
|
if (sigma < 0.0) {
|
|
|
throw new IllegalArgumentException("[sigma] must be greater than or equal to 0. Found [" + sigma + "] in [" + name + "]");
|
|
@@ -64,19 +83,6 @@ public class ExtendedStatsAggregatorBuilder
|
|
|
return new ExtendedStatsAggregatorFactory(name, type, config, sigma, context, parent, subFactoriesBuilder, metaData);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected ExtendedStatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
|
|
|
- ValueType targetValueType, StreamInput in) throws IOException {
|
|
|
- ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregatorBuilder(name);
|
|
|
- factory.sigma = in.readDouble();
|
|
|
- return factory;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void innerWriteTo(StreamOutput out) throws IOException {
|
|
|
- out.writeDouble(sigma);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.field(ExtendedStatsAggregator.SIGMA_FIELD.getPreferredName(), sigma);
|
|
@@ -93,4 +99,9 @@ public class ExtendedStatsAggregatorBuilder
|
|
|
ExtendedStatsAggregatorBuilder other = (ExtendedStatsAggregatorBuilder) obj;
|
|
|
return Objects.equals(sigma, other.sigma);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getWriteableName() {
|
|
|
+ return NAME;
|
|
|
+ }
|
|
|
}
|