|
@@ -27,7 +27,6 @@ import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
|
|
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -53,7 +52,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
|
|
|
String[] bucketsPaths = null;
|
|
|
String format = null;
|
|
|
GapPolicy gapPolicy = null;
|
|
|
- Map<String, Object> leftover = new HashMap<>(5);
|
|
|
+ Map<String, Object> params = new HashMap<>(5);
|
|
|
|
|
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
|
if (token == XContentParser.Token.FIELD_NAME) {
|
|
@@ -66,7 +65,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
|
|
|
} else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
|
|
|
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
|
|
|
} else {
|
|
|
- leftover.put(currentFieldName, parser.text());
|
|
|
+ parseToken(pipelineAggregatorName, parser, context, currentFieldName, token, params);
|
|
|
}
|
|
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
|
|
if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
|
@@ -77,10 +76,10 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
|
|
|
}
|
|
|
bucketsPaths = paths.toArray(new String[paths.size()]);
|
|
|
} else {
|
|
|
- leftover.put(currentFieldName, parser.list());
|
|
|
+ parseToken(pipelineAggregatorName, parser, context, currentFieldName, token, params);
|
|
|
}
|
|
|
} else {
|
|
|
- leftover.put(currentFieldName, parser.objectText());
|
|
|
+ parseToken(pipelineAggregatorName, parser, context, currentFieldName, token, params);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -89,30 +88,32 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
|
|
|
"Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for aggregation [" + pipelineAggregatorName + "]");
|
|
|
}
|
|
|
|
|
|
- BucketMetricsPipelineAggregatorBuilder<?> factory = null;
|
|
|
- try {
|
|
|
- factory = buildFactory(pipelineAggregatorName, bucketsPaths[0], leftover);
|
|
|
- if (format != null) {
|
|
|
- factory.format(format);
|
|
|
- }
|
|
|
- if (gapPolicy != null) {
|
|
|
- factory.gapPolicy(gapPolicy);
|
|
|
- }
|
|
|
- } catch (ParseException exception) {
|
|
|
- throw new ParsingException(parser.getTokenLocation(),
|
|
|
- "Could not parse settings for aggregation [" + pipelineAggregatorName + "].", exception);
|
|
|
+ BucketMetricsPipelineAggregatorBuilder<?> factory = buildFactory(pipelineAggregatorName, bucketsPaths[0], params);
|
|
|
+ if (format != null) {
|
|
|
+ factory.format(format);
|
|
|
}
|
|
|
-
|
|
|
- if (leftover.size() > 0) {
|
|
|
- throw new ParsingException(parser.getTokenLocation(),
|
|
|
- "Unexpected tokens " + leftover.keySet() + " in [" + pipelineAggregatorName + "].");
|
|
|
+ if (gapPolicy != null) {
|
|
|
+ factory.gapPolicy(gapPolicy);
|
|
|
}
|
|
|
+
|
|
|
assert(factory != null);
|
|
|
|
|
|
return factory;
|
|
|
}
|
|
|
|
|
|
protected abstract BucketMetricsPipelineAggregatorBuilder<?> buildFactory(String pipelineAggregatorName, String bucketsPaths,
|
|
|
- Map<String, Object> unparsedParams) throws ParseException;
|
|
|
+ Map<String, Object> params);
|
|
|
|
|
|
+ protected boolean token(XContentParser parser, QueryParseContext context, String field,
|
|
|
+ XContentParser.Token token, Map<String, Object> params) throws IOException {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void parseToken(String aggregationName, XContentParser parser, QueryParseContext context, String currentFieldName,
|
|
|
+ XContentParser.Token currentToken, Map<String, Object> params) throws IOException {
|
|
|
+ if (token(parser, context, currentFieldName, currentToken, params) == false) {
|
|
|
+ throw new ParsingException(parser.getTokenLocation(),
|
|
|
+ "Unexpected token " + currentToken + " [" + currentFieldName + "] in [" + aggregationName + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|