From 8d26996afddfceb5ef97e27008a906e83f6cd6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 3 Jul 2017 17:31:18 +0200 Subject: [PATCH] Remove QueryParseContext (elastic/x-pack-elasticsearch#1895) This is the x-pack side of elastic/elasticsearch#25486. Original commit: elastic/x-pack-elasticsearch@c90a3e096b942dda7149c8946b054fbbbf413303 --- plugin/.gitignore | 1 + .../xpack/graph/rest/action/RestGraphAction.java | 13 +++++-------- .../xpack/ml/datafeed/DatafeedConfig.java | 5 ++--- .../xpack/ml/datafeed/DatafeedUpdate.java | 5 ++--- .../search/WatcherSearchTemplateService.java | 3 +-- 5 files changed, 11 insertions(+), 16 deletions(-) create mode 100644 plugin/.gitignore diff --git a/plugin/.gitignore b/plugin/.gitignore new file mode 100644 index 00000000000..ae3c1726048 --- /dev/null +++ b/plugin/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/plugin/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/plugin/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index 54f1cbcc56c..49321cd3c5d 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; @@ -89,7 +88,6 @@ public class RestGraphAction extends XPackRestHandler { Hop currentHop = graphRequest.createNextHop(null); try (XContentParser parser = request.contentOrSourceParamParser()) { - QueryParseContext context = new QueryParseContext(parser); XContentParser.Token token = parser.nextToken(); @@ -97,15 +95,14 @@ public class RestGraphAction extends XPackRestHandler { throw new ElasticsearchParseException("failed to parse search source. source must be an object, but found [{}] instead", token.name()); } - parseHop(parser, context, currentHop, graphRequest); + parseHop(parser, currentHop, graphRequest); } graphRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); return channel -> client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel)); } - private void parseHop(XContentParser parser, QueryParseContext context, Hop currentHop, - GraphExploreRequest graphRequest) throws IOException { + private void parseHop(XContentParser parser, Hop currentHop, GraphExploreRequest graphRequest) throws IOException { String fieldName = null; XContentParser.Token token; @@ -123,13 +120,13 @@ public class RestGraphAction extends XPackRestHandler { if (QUERY_FIELD.match(fieldName)) { currentHop.guidingQuery(parseInnerQueryBuilder(parser)); } else if (CONNECTIONS_FIELD.match(fieldName)) { - parseHop(parser, context, graphRequest.createNextHop(null), graphRequest); + parseHop(parser, graphRequest.createNextHop(null), graphRequest); } else if (CONTROLS_FIELD.match(fieldName)) { if (currentHop.getParentHop() != null) { throw new ElasticsearchParseException( "Controls are a global setting that can only be set in the root " + fieldName, token.name()); } - parseControls(parser, context, graphRequest); + parseControls(parser, graphRequest); } else { throw new ElasticsearchParseException("Illegal object property in graph definition " + fieldName, token.name()); @@ -274,7 +271,7 @@ public class RestGraphAction extends XPackRestHandler { } - private void parseControls(XContentParser parser, QueryParseContext context, GraphExploreRequest graphRequest) throws IOException { + private void parseControls(XContentParser parser, GraphExploreRequest graphRequest) throws IOException { XContentParser.Token token; String fieldName = null; diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfig.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfig.java index 0e98840d5d7..8519575ed40 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfig.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfig.java @@ -21,7 +21,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; @@ -89,9 +88,9 @@ public class DatafeedConfig extends AbstractDiffable implements builder.setFrequency(TimeValue.parseTimeValue(val, FREQUENCY.getPreferredName())), FREQUENCY); PARSER.declareObject(Builder::setQuery, (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p), QUERY); - PARSER.declareObject(Builder::setAggregations, (p, c) -> AggregatorFactories.parseAggregators(new QueryParseContext(p)), + PARSER.declareObject(Builder::setAggregations, (p, c) -> AggregatorFactories.parseAggregators(p), AGGREGATIONS); - PARSER.declareObject(Builder::setAggregations,(p, c) -> AggregatorFactories.parseAggregators(new QueryParseContext(p)), AGGS); + PARSER.declareObject(Builder::setAggregations,(p, c) -> AggregatorFactories.parseAggregators(p), AGGS); PARSER.declareObject(Builder::setScriptFields, (p, c) -> { List parsedScriptFields = new ArrayList<>(); while (p.nextToken() != XContentParser.Token.END_OBJECT) { diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedUpdate.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedUpdate.java index 5da3dd7bb26..2d732c4a5dc 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedUpdate.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedUpdate.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.xpack.ml.job.config.Job; @@ -51,9 +50,9 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { TimeValue.parseTimeValue(val, DatafeedConfig.FREQUENCY.getPreferredName())), DatafeedConfig.FREQUENCY); PARSER.declareObject(Builder::setQuery, (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p), DatafeedConfig.QUERY); - PARSER.declareObject(Builder::setAggregations, (p, c) -> AggregatorFactories.parseAggregators(new QueryParseContext(p)), + PARSER.declareObject(Builder::setAggregations, (p, c) -> AggregatorFactories.parseAggregators(p), DatafeedConfig.AGGREGATIONS); - PARSER.declareObject(Builder::setAggregations,(p, c) -> AggregatorFactories.parseAggregators(new QueryParseContext(p)), + PARSER.declareObject(Builder::setAggregations,(p, c) -> AggregatorFactories.parseAggregators(p), DatafeedConfig.AGGS); PARSER.declareObject(Builder::setScriptFields, (p, c) -> { List parsedScriptFields = new ArrayList<>(); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java b/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java index 36750e878a9..b8fd2591ed2 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.TemplateScript; @@ -63,7 +62,7 @@ public class WatcherSearchTemplateService extends AbstractComponent { BytesReference source = request.getSearchSource(); if (source != null && source.length() > 0) { try (XContentParser parser = XContentFactory.xContent(source).createParser(xContentRegistry, source)) { - sourceBuilder.parseXContent(new QueryParseContext(parser)); + sourceBuilder.parseXContent(parser); searchRequest.source(sourceBuilder); } }