Cut moving_avg aggregation to registerPipelineAggregation
and remove its PROTOTYPE. Relates to #17085
This commit is contained in:
parent
b8003de409
commit
08d3bf937d
|
@ -217,8 +217,8 @@ import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSu
|
||||||
import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator;
|
import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder;
|
import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative;
|
import org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator;
|
||||||
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator;
|
import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator;
|
||||||
|
@ -511,7 +511,9 @@ public class SearchModule extends AbstractModule {
|
||||||
registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(),
|
registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(),
|
||||||
ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
||||||
registerPipelineParser(new PercentilesBucketParser());
|
registerPipelineParser(new PercentilesBucketParser());
|
||||||
registerPipelineParser(new MovAvgParser(movAvgModelParserMapper));
|
registerPipelineAggregation(MovAvgPipelineAggregatorBuilder::new,
|
||||||
|
(n, c) -> MovAvgPipelineAggregatorBuilder.parse(movAvgModelParserMapper, n, c),
|
||||||
|
MovAvgPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME);
|
||||||
registerPipelineAggregation(CumulativeSumPipelineAggregatorBuilder::new, CumulativeSumPipelineAggregatorBuilder::parse,
|
registerPipelineAggregation(CumulativeSumPipelineAggregatorBuilder::new, CumulativeSumPipelineAggregatorBuilder::parse,
|
||||||
CumulativeSumPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
CumulativeSumPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
||||||
registerPipelineAggregation(BucketScriptPipelineAggregatorBuilder::new, BucketScriptPipelineAggregatorBuilder::parse,
|
registerPipelineAggregation(BucketScriptPipelineAggregatorBuilder::new, BucketScriptPipelineAggregatorBuilder::parse,
|
||||||
|
|
|
@ -1,183 +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.movavg;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseField;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
|
||||||
import org.elasticsearch.index.query.QueryParseContext;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MovAvgParser implements PipelineAggregator.Parser {
|
|
||||||
|
|
||||||
public static final ParseField MODEL = new ParseField("model");
|
|
||||||
public static final ParseField WINDOW = new ParseField("window");
|
|
||||||
public static final ParseField SETTINGS = new ParseField("settings");
|
|
||||||
public static final ParseField PREDICT = new ParseField("predict");
|
|
||||||
public static final ParseField MINIMIZE = new ParseField("minimize");
|
|
||||||
|
|
||||||
private final MovAvgModelParserMapper movAvgModelParserMapper;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public MovAvgParser(MovAvgModelParserMapper movAvgModelParserMapper) {
|
|
||||||
this.movAvgModelParserMapper = movAvgModelParserMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String type() {
|
|
||||||
return MovAvgPipelineAggregator.TYPE.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MovAvgPipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException {
|
|
||||||
XContentParser parser = context.parser();
|
|
||||||
XContentParser.Token token;
|
|
||||||
String currentFieldName = null;
|
|
||||||
String[] bucketsPaths = null;
|
|
||||||
String format = null;
|
|
||||||
|
|
||||||
GapPolicy gapPolicy = null;
|
|
||||||
Integer window = null;
|
|
||||||
Map<String, Object> settings = null;
|
|
||||||
String model = null;
|
|
||||||
Integer predict = null;
|
|
||||||
Boolean minimize = null;
|
|
||||||
|
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
|
||||||
currentFieldName = parser.currentName();
|
|
||||||
} else if (token == XContentParser.Token.VALUE_NUMBER) {
|
|
||||||
if (context.getParseFieldMatcher().match(currentFieldName, WINDOW)) {
|
|
||||||
window = parser.intValue();
|
|
||||||
if (window <= 0) {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive, "
|
|
||||||
+ "non-zero integer. Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
|
|
||||||
}
|
|
||||||
} else if (context.getParseFieldMatcher().match(currentFieldName, PREDICT)) {
|
|
||||||
predict = parser.intValue();
|
|
||||||
if (predict <= 0) {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive integer."
|
|
||||||
+ " Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
|
||||||
}
|
|
||||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
|
||||||
if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
|
|
||||||
format = parser.text();
|
|
||||||
} else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
|
||||||
bucketsPaths = new String[] { parser.text() };
|
|
||||||
} else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
|
|
||||||
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
|
|
||||||
} else if (context.getParseFieldMatcher().match(currentFieldName, MODEL)) {
|
|
||||||
model = parser.text();
|
|
||||||
} else {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
|
||||||
}
|
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
|
||||||
if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
|
||||||
List<String> paths = new ArrayList<>();
|
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
|
||||||
String path = parser.text();
|
|
||||||
paths.add(path);
|
|
||||||
}
|
|
||||||
bucketsPaths = paths.toArray(new String[paths.size()]);
|
|
||||||
} else {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
|
||||||
}
|
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
|
||||||
if (context.getParseFieldMatcher().match(currentFieldName, SETTINGS)) {
|
|
||||||
settings = parser.map();
|
|
||||||
} else {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
|
||||||
}
|
|
||||||
} else if (token == XContentParser.Token.VALUE_BOOLEAN) {
|
|
||||||
if (context.getParseFieldMatcher().match(currentFieldName, MINIMIZE)) {
|
|
||||||
minimize = parser.booleanValue();
|
|
||||||
} else {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unexpected token " + token + " in [" + pipelineAggregatorName + "].");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bucketsPaths == null) {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
|
|
||||||
+ "] for movingAvg aggregation [" + pipelineAggregatorName + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
MovAvgPipelineAggregatorBuilder factory =
|
|
||||||
new MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]);
|
|
||||||
if (format != null) {
|
|
||||||
factory.format(format);
|
|
||||||
}
|
|
||||||
if (gapPolicy != null) {
|
|
||||||
factory.gapPolicy(gapPolicy);
|
|
||||||
}
|
|
||||||
if (window != null) {
|
|
||||||
factory.window(window);
|
|
||||||
}
|
|
||||||
if (predict != null) {
|
|
||||||
factory.predict(predict);
|
|
||||||
}
|
|
||||||
if (model != null) {
|
|
||||||
MovAvgModel.AbstractModelParser modelParser = movAvgModelParserMapper.get(model);
|
|
||||||
if (modelParser == null) {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"Unknown model [" + model + "] specified. Valid options are:" + movAvgModelParserMapper.getAllNames().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
MovAvgModel movAvgModel;
|
|
||||||
try {
|
|
||||||
movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher());
|
|
||||||
} catch (ParseException exception) {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception);
|
|
||||||
}
|
|
||||||
factory.model(movAvgModel);
|
|
||||||
}
|
|
||||||
if (minimize != null) {
|
|
||||||
factory.minimize(minimize);
|
|
||||||
}
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MovAvgPipelineAggregatorBuilder getFactoryPrototype() {
|
|
||||||
return MovAvgPipelineAggregatorBuilder.PROTOTYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,28 +19,45 @@
|
||||||
|
|
||||||
package org.elasticsearch.search.aggregations.pipeline.movavg;
|
package org.elasticsearch.search.aggregations.pipeline.movavg;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.ParseField;
|
||||||
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
import org.elasticsearch.index.query.QueryParseContext;
|
||||||
import org.elasticsearch.search.DocValueFormat;
|
import org.elasticsearch.search.DocValueFormat;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||||
import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory;
|
import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory;
|
||||||
|
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
|
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelBuilder;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelBuilder;
|
||||||
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelStreams;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelStreams;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder<MovAvgPipelineAggregatorBuilder> {
|
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
|
||||||
|
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT;
|
||||||
|
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY;
|
||||||
|
|
||||||
static final MovAvgPipelineAggregatorBuilder PROTOTYPE = new MovAvgPipelineAggregatorBuilder("", "");
|
public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder<MovAvgPipelineAggregatorBuilder> {
|
||||||
|
public static final String NAME = MovAvgPipelineAggregator.TYPE.name();
|
||||||
|
public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME);
|
||||||
|
|
||||||
|
public static final ParseField MODEL = new ParseField("model");
|
||||||
|
private static final ParseField WINDOW = new ParseField("window");
|
||||||
|
public static final ParseField SETTINGS = new ParseField("settings");
|
||||||
|
private static final ParseField PREDICT = new ParseField("predict");
|
||||||
|
private static final ParseField MINIMIZE = new ParseField("minimize");
|
||||||
|
|
||||||
private String format;
|
private String format;
|
||||||
private GapPolicy gapPolicy = GapPolicy.SKIP;
|
private GapPolicy gapPolicy = GapPolicy.SKIP;
|
||||||
|
@ -50,11 +67,35 @@ public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder<M
|
||||||
private Boolean minimize;
|
private Boolean minimize;
|
||||||
|
|
||||||
public MovAvgPipelineAggregatorBuilder(String name, String bucketsPath) {
|
public MovAvgPipelineAggregatorBuilder(String name, String bucketsPath) {
|
||||||
this(name, new String[] { bucketsPath });
|
super(name, MovAvgPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
|
||||||
}
|
}
|
||||||
|
|
||||||
private MovAvgPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
|
/**
|
||||||
super(name, MovAvgPipelineAggregator.TYPE.name(), bucketsPaths);
|
* Read from a stream.
|
||||||
|
*/
|
||||||
|
public MovAvgPipelineAggregatorBuilder(StreamInput in) throws IOException {
|
||||||
|
super(in, MovAvgPipelineAggregator.TYPE.name());
|
||||||
|
format = in.readOptionalString();
|
||||||
|
gapPolicy = GapPolicy.readFrom(in);
|
||||||
|
window = in.readVInt();
|
||||||
|
model = MovAvgModelStreams.read(in);
|
||||||
|
predict = in.readVInt();
|
||||||
|
minimize = in.readOptionalBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeOptionalString(format);
|
||||||
|
gapPolicy.writeTo(out);
|
||||||
|
out.writeVInt(window);
|
||||||
|
model.writeTo(out);
|
||||||
|
out.writeVInt(predict);
|
||||||
|
out.writeOptionalBoolean(minimize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean usesNewStyleSerialization() {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,40 +287,138 @@ public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder<M
|
||||||
@Override
|
@Override
|
||||||
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
|
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
builder.field(MovAvgParser.FORMAT.getPreferredName(), format);
|
builder.field(FORMAT.getPreferredName(), format);
|
||||||
}
|
}
|
||||||
builder.field(MovAvgParser.GAP_POLICY.getPreferredName(), gapPolicy.getName());
|
builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
|
||||||
model.toXContent(builder, params);
|
model.toXContent(builder, params);
|
||||||
builder.field(MovAvgParser.WINDOW.getPreferredName(), window);
|
builder.field(WINDOW.getPreferredName(), window);
|
||||||
if (predict > 0) {
|
if (predict > 0) {
|
||||||
builder.field(MovAvgParser.PREDICT.getPreferredName(), predict);
|
builder.field(PREDICT.getPreferredName(), predict);
|
||||||
}
|
}
|
||||||
if (minimize != null) {
|
if (minimize != null) {
|
||||||
builder.field(MovAvgParser.MINIMIZE.getPreferredName(), minimize);
|
builder.field(MINIMIZE.getPreferredName(), minimize);
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static MovAvgPipelineAggregatorBuilder parse(MovAvgModelParserMapper movAvgModelParserMapper, String pipelineAggregatorName,
|
||||||
protected MovAvgPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
|
QueryParseContext context) throws IOException {
|
||||||
MovAvgPipelineAggregatorBuilder factory = new MovAvgPipelineAggregatorBuilder(name, bucketsPaths);
|
XContentParser parser = context.parser();
|
||||||
factory.format = in.readOptionalString();
|
XContentParser.Token token;
|
||||||
factory.gapPolicy = GapPolicy.readFrom(in);
|
String currentFieldName = null;
|
||||||
factory.window = in.readVInt();
|
String[] bucketsPaths = null;
|
||||||
factory.model = MovAvgModelStreams.read(in);
|
String format = null;
|
||||||
factory.predict = in.readVInt();
|
|
||||||
factory.minimize = in.readOptionalBoolean();
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
GapPolicy gapPolicy = null;
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
Integer window = null;
|
||||||
out.writeOptionalString(format);
|
Map<String, Object> settings = null;
|
||||||
gapPolicy.writeTo(out);
|
String model = null;
|
||||||
out.writeVInt(window);
|
Integer predict = null;
|
||||||
model.writeTo(out);
|
Boolean minimize = null;
|
||||||
out.writeVInt(predict);
|
|
||||||
out.writeOptionalBoolean(minimize);
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
currentFieldName = parser.currentName();
|
||||||
|
} else if (token == XContentParser.Token.VALUE_NUMBER) {
|
||||||
|
if (context.getParseFieldMatcher().match(currentFieldName, WINDOW)) {
|
||||||
|
window = parser.intValue();
|
||||||
|
if (window <= 0) {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive, "
|
||||||
|
+ "non-zero integer. Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
|
||||||
|
}
|
||||||
|
} else if (context.getParseFieldMatcher().match(currentFieldName, PREDICT)) {
|
||||||
|
predict = parser.intValue();
|
||||||
|
if (predict <= 0) {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive integer."
|
||||||
|
+ " Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
||||||
|
}
|
||||||
|
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||||
|
if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
|
||||||
|
format = parser.text();
|
||||||
|
} else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
||||||
|
bucketsPaths = new String[] { parser.text() };
|
||||||
|
} else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
|
||||||
|
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
|
||||||
|
} else if (context.getParseFieldMatcher().match(currentFieldName, MODEL)) {
|
||||||
|
model = parser.text();
|
||||||
|
} else {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
||||||
|
}
|
||||||
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
|
if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
||||||
|
List<String> paths = new ArrayList<>();
|
||||||
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
String path = parser.text();
|
||||||
|
paths.add(path);
|
||||||
|
}
|
||||||
|
bucketsPaths = paths.toArray(new String[paths.size()]);
|
||||||
|
} else {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
||||||
|
}
|
||||||
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
|
if (context.getParseFieldMatcher().match(currentFieldName, SETTINGS)) {
|
||||||
|
settings = parser.map();
|
||||||
|
} else {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
||||||
|
}
|
||||||
|
} else if (token == XContentParser.Token.VALUE_BOOLEAN) {
|
||||||
|
if (context.getParseFieldMatcher().match(currentFieldName, MINIMIZE)) {
|
||||||
|
minimize = parser.booleanValue();
|
||||||
|
} else {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unexpected token " + token + " in [" + pipelineAggregatorName + "].");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bucketsPaths == null) {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
|
||||||
|
+ "] for movingAvg aggregation [" + pipelineAggregatorName + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
MovAvgPipelineAggregatorBuilder factory =
|
||||||
|
new MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]);
|
||||||
|
if (format != null) {
|
||||||
|
factory.format(format);
|
||||||
|
}
|
||||||
|
if (gapPolicy != null) {
|
||||||
|
factory.gapPolicy(gapPolicy);
|
||||||
|
}
|
||||||
|
if (window != null) {
|
||||||
|
factory.window(window);
|
||||||
|
}
|
||||||
|
if (predict != null) {
|
||||||
|
factory.predict(predict);
|
||||||
|
}
|
||||||
|
if (model != null) {
|
||||||
|
MovAvgModel.AbstractModelParser modelParser = movAvgModelParserMapper.get(model);
|
||||||
|
if (modelParser == null) {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(),
|
||||||
|
"Unknown model [" + model + "] specified. Valid options are:" + movAvgModelParserMapper.getAllNames().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
MovAvgModel movAvgModel;
|
||||||
|
try {
|
||||||
|
movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher());
|
||||||
|
} catch (ParseException exception) {
|
||||||
|
throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception);
|
||||||
|
}
|
||||||
|
factory.model(movAvgModel);
|
||||||
|
}
|
||||||
|
if (minimize != null) {
|
||||||
|
factory.minimize(minimize);
|
||||||
|
}
|
||||||
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -298,4 +437,8 @@ public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder<M
|
||||||
&& Objects.equals(minimize, other.minimize);
|
&& Objects.equals(minimize, other.minimize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getWriteableName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -115,8 +115,8 @@ public class EwmaModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
builder.startObject(MovAvgParser.SETTINGS.getPreferredName());
|
builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName());
|
||||||
builder.field("alpha", alpha);
|
builder.field("alpha", alpha);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -188,8 +188,8 @@ public class EwmaModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
builder.startObject(MovAvgParser.SETTINGS.getPreferredName());
|
builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName());
|
||||||
builder.field("alpha", alpha);
|
builder.field("alpha", alpha);
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -176,8 +176,8 @@ public class HoltLinearModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
builder.startObject(MovAvgParser.SETTINGS.getPreferredName());
|
builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName());
|
||||||
builder.field("alpha", alpha);
|
builder.field("alpha", alpha);
|
||||||
builder.field("beta", beta);
|
builder.field("beta", beta);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
@ -266,8 +266,8 @@ public class HoltLinearModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
builder.startObject(MovAvgParser.SETTINGS.getPreferredName());
|
builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName());
|
||||||
builder.field("alpha", alpha);
|
builder.field("alpha", alpha);
|
||||||
builder.field("beta", beta);
|
builder.field("beta", beta);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -346,8 +346,8 @@ public class HoltWintersModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
builder.startObject(MovAvgParser.SETTINGS.getPreferredName());
|
builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName());
|
||||||
builder.field("alpha", alpha);
|
builder.field("alpha", alpha);
|
||||||
builder.field("beta", beta);
|
builder.field("beta", beta);
|
||||||
builder.field("gamma", gamma);
|
builder.field("gamma", gamma);
|
||||||
|
@ -498,8 +498,8 @@ public class HoltWintersModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
builder.startObject(MovAvgParser.SETTINGS.getPreferredName());
|
builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName());
|
||||||
builder.field("alpha", alpha);
|
builder.field("alpha", alpha);
|
||||||
builder.field("beta", beta);
|
builder.field("beta", beta);
|
||||||
builder.field("gamma", gamma);
|
builder.field("gamma", gamma);
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -97,7 +97,7 @@ public class LinearModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public class LinearModel extends MovAvgModel {
|
||||||
public static class LinearModelBuilder implements MovAvgModelBuilder {
|
public static class LinearModelBuilder implements MovAvgModelBuilder {
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.search.aggregations.pipeline.movavg.models;
|
package org.elasticsearch.search.aggregations.pipeline.movavg.models;
|
||||||
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -34,7 +33,6 @@ public class MovAvgModelParserMapper {
|
||||||
|
|
||||||
protected Map<String, MovAvgModel.AbstractModelParser> movAvgParsers;
|
protected Map<String, MovAvgModel.AbstractModelParser> movAvgParsers;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public MovAvgModelParserMapper(Set<MovAvgModel.AbstractModelParser> parsers) {
|
public MovAvgModelParserMapper(Set<MovAvgModel.AbstractModelParser> parsers) {
|
||||||
Map<String, MovAvgModel.AbstractModelParser> map = new HashMap<>();
|
Map<String, MovAvgModel.AbstractModelParser> map = new HashMap<>();
|
||||||
add(map, new SimpleModel.SimpleModelParser());
|
add(map, new SimpleModel.SimpleModelParser());
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
|
import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -90,7 +90,7 @@ public class SimpleModel extends MovAvgModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public class SimpleModel extends MovAvgModel {
|
||||||
public static class SimpleModelBuilder implements MovAvgModelBuilder {
|
public static class SimpleModelBuilder implements MovAvgModelBuilder {
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue