From 7fde410586af9f90c01f9d7df3f9dbb373836455 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 15 Aug 2016 21:21:11 -0700 Subject: [PATCH] Internal: Consolidate search parser registries Parsing a search request is currently split up among a number of classes, using multiple public static methods, which take multiple regstries of elements that may appear in the search request like query parsers and aggregations. This change begins consolidating all this code by collapsing the registries normally used for parsing search requests into a single SearchRequestParsers class. It is also made available to plugin services to enable templating of search requests. Eventually all of the actual parsing logic should move to the class, and the registries should be hidden, but for now they are at least co-located to reduce the number of objects that must be passed around. --- .../java/org/elasticsearch/node/Node.java | 2 +- .../org/elasticsearch/plugins/Plugin.java | 5 +- .../action/search/RestMultiSearchAction.java | 25 ++++---- .../rest/action/search/RestSearchAction.java | 23 +++---- .../action/suggest/RestSuggestAction.java | 13 ++-- .../elasticsearch/search/SearchModule.java | 13 ++-- .../search/SearchRequestParsers.java | 63 +++++++++++++++++++ .../search/MultiSearchRequestTests.java | 7 ++- .../AggregationCollectorTests.java | 3 +- .../aggregations/AggregatorParsingTests.java | 3 +- .../aggregations/BaseAggregationTestCase.java | 3 +- .../BasePipelineAggregationTestCase.java | 3 +- .../builder/SearchSourceBuilderTests.java | 47 +++++++------- .../mustache/RestSearchTemplateAction.java | 14 ++--- .../TransportSearchTemplateAction.java | 15 ++--- .../TransportMultiPercolateAction.java | 19 +++--- .../percolator/TransportPercolateAction.java | 12 ++-- .../AbstractBaseReindexRestHandler.java | 12 ++-- .../AbstractBulkByQueryRestHandler.java | 11 ++-- .../reindex/RestDeleteByQueryAction.java | 6 +- .../index/reindex/RestReindexAction.java | 27 ++++---- .../reindex/RestUpdateByQueryAction.java | 6 +- .../index/reindex/RestReindexActionTests.java | 5 +- 23 files changed, 191 insertions(+), 146 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 955676b0166..d59937a32db 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -347,7 +347,7 @@ public class Node implements Closeable { client = new NodeClient(settings, threadPool); Collection pluginComponents = pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService, - scriptModule.getScriptService()).stream()) + scriptModule.getScriptService(), searchModule.getSearchRequestParsers()).stream()) .collect(Collectors.toList()); modules.add(b -> { b.bind(PluginsService.class).toInstance(pluginsService); diff --git a/core/src/main/java/org/elasticsearch/plugins/Plugin.java b/core/src/main/java/org/elasticsearch/plugins/Plugin.java index b7223541644..32799422db0 100644 --- a/core/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -39,6 +39,7 @@ import org.elasticsearch.index.IndexModule; import org.elasticsearch.indices.analysis.AnalysisModule; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; @@ -84,9 +85,11 @@ public abstract class Plugin { * @param threadPool A service to allow retrieving an executor to run an async action * @param resourceWatcherService A service to watch for changes to node local files * @param scriptService A service to allow running scripts on the local node + * @param searchRequestParsers Parsers for search requests which may be used to templatize search requests */ public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, - ResourceWatcherService resourceWatcherService, ScriptService scriptService) { + ResourceWatcherService resourceWatcherService, ScriptService scriptService, + SearchRequestParsers searchRequestParsers) { return Collections.emptyList(); } diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 52965193a2e..097aa045d85 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -40,6 +40,7 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestToXContentListener; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.suggest.Suggesters; @@ -59,16 +60,12 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestMultiSearchAction extends BaseRestHandler { private final boolean allowExplicitIndex; - private final IndicesQueriesRegistry indicesQueriesRegistry; - private final AggregatorParsers aggParsers; - private final Suggesters suggesters; + private final SearchRequestParsers searchRequestParsers; @Inject - public RestMultiSearchAction(Settings settings, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry, - AggregatorParsers aggParsers, Suggesters suggesters) { + public RestMultiSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) { super(settings); - this.aggParsers = aggParsers; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; controller.registerHandler(GET, "/_msearch", this); controller.registerHandler(POST, "/_msearch", this); @@ -78,13 +75,11 @@ public class RestMultiSearchAction extends BaseRestHandler { controller.registerHandler(POST, "/{index}/{type}/_msearch", this); this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); - this.indicesQueriesRegistry = indicesQueriesRegistry; } @Override public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) throws Exception { - MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, indicesQueriesRegistry, parseFieldMatcher, - aggParsers, suggesters); + MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, searchRequestParsers, parseFieldMatcher); client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel)); } @@ -92,8 +87,8 @@ public class RestMultiSearchAction extends BaseRestHandler { * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest} */ public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex, - IndicesQueriesRegistry queriesRegistry, ParseFieldMatcher parseFieldMatcher, - AggregatorParsers aggParsers, Suggesters suggesters) throws IOException { + SearchRequestParsers searchRequestParsers, + ParseFieldMatcher parseFieldMatcher) throws IOException { MultiSearchRequest multiRequest = new MultiSearchRequest(); if (restRequest.hasParam("max_concurrent_searches")) { @@ -102,8 +97,10 @@ public class RestMultiSearchAction extends BaseRestHandler { parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, bytes) -> { try (XContentParser requestParser = XContentFactory.xContent(bytes).createParser(bytes)) { - final QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry, requestParser, parseFieldMatcher); - searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext, aggParsers, suggesters)); + final QueryParseContext queryParseContext = new QueryParseContext(searchRequestParsers.queryParsers, + requestParser, parseFieldMatcher); + searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext, + searchRequestParsers.aggParsers, searchRequestParsers.suggesters)); multiRequest.add(searchRequest); } catch (IOException e) { throw new ElasticsearchParseException("Exception when parsing search request", e); diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 7a73d306221..445f5ce3377 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -41,6 +41,7 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestStatusToXContentListener; import org.elasticsearch.search.Scroll; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; @@ -63,17 +64,12 @@ import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion; */ public class RestSearchAction extends BaseRestHandler { - private final IndicesQueriesRegistry queryRegistry; - private final AggregatorParsers aggParsers; - private final Suggesters suggesters; + private final SearchRequestParsers searchRequestParsers; @Inject - public RestSearchAction(Settings settings, RestController controller, IndicesQueriesRegistry queryRegistry, - AggregatorParsers aggParsers, Suggesters suggesters) { + public RestSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) { super(settings); - this.queryRegistry = queryRegistry; - this.aggParsers = aggParsers; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; controller.registerHandler(GET, "/_search", this); controller.registerHandler(POST, "/_search", this); controller.registerHandler(GET, "/{index}/_search", this); @@ -86,7 +82,7 @@ public class RestSearchAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) throws IOException { SearchRequest searchRequest = new SearchRequest(); BytesReference restContent = RestActions.hasBodyContent(request) ? RestActions.getRestContent(request) : null; - parseSearchRequest(searchRequest, queryRegistry, request, parseFieldMatcher, aggParsers, suggesters, restContent); + parseSearchRequest(searchRequest, request, searchRequestParsers, parseFieldMatcher, restContent); client.search(searchRequest, new RestStatusToXContentListener<>(channel)); } @@ -99,9 +95,8 @@ public class RestSearchAction extends BaseRestHandler { * content is read from the request using * RestAction.hasBodyContent. */ - public static void parseSearchRequest(SearchRequest searchRequest, IndicesQueriesRegistry indicesQueriesRegistry, RestRequest request, - ParseFieldMatcher parseFieldMatcher, AggregatorParsers aggParsers, Suggesters suggesters, BytesReference restContent) - throws IOException { + public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, SearchRequestParsers searchRequestParsers, + ParseFieldMatcher parseFieldMatcher, BytesReference restContent) throws IOException { if (searchRequest.source() == null) { searchRequest.source(new SearchSourceBuilder()); @@ -109,8 +104,8 @@ public class RestSearchAction extends BaseRestHandler { searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index"))); if (restContent != null) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); - searchRequest.source().parseXContent(context, aggParsers, suggesters); + QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher); + searchRequest.source().parseXContent(context, searchRequestParsers.aggParsers, searchRequestParsers.suggesters); } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java b/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java index f6acfc6daf5..aadd7f08199 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java @@ -41,6 +41,7 @@ import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestBuilderListener; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.SuggestBuilder; @@ -57,15 +58,13 @@ import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastSh */ public class RestSuggestAction extends BaseRestHandler { - private final IndicesQueriesRegistry queryRegistry; - private final Suggesters suggesters; + private final SearchRequestParsers searchRequestParsers; @Inject public RestSuggestAction(Settings settings, RestController controller, - IndicesQueriesRegistry queryRegistry, Suggesters suggesters) { + SearchRequestParsers searchRequestParsers) { super(settings); - this.queryRegistry = queryRegistry; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; controller.registerHandler(POST, "/_suggest", this); controller.registerHandler(GET, "/_suggest", this); controller.registerHandler(POST, "/{index}/_suggest", this); @@ -79,8 +78,8 @@ public class RestSuggestAction extends BaseRestHandler { if (RestActions.hasBodyContent(request)) { final BytesReference sourceBytes = RestActions.getRestContent(request); try (XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes)) { - final QueryParseContext context = new QueryParseContext(queryRegistry, parser, parseFieldMatcher); - searchRequest.source().suggest(SuggestBuilder.fromXContent(context, suggesters)); + final QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher); + searchRequest.source().suggest(SuggestBuilder.fromXContent(context, searchRequestParsers.suggesters)); } } else { throw new IllegalArgumentException("no content or source provided to execute suggestion"); diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 5a5137ea571..ab33fcb328d 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -309,6 +309,7 @@ public class SearchModule extends AbstractModule { private final Settings settings; private final List namedWriteables = new ArrayList<>(); + private final SearchRequestParsers searchRequestParsers; public static final Setting INDICES_MAX_CLAUSE_COUNT_SETTING = Setting.intSetting("indices.query.bool.max_clause_count", 1024, 1, Integer.MAX_VALUE, Setting.Property.NodeScope); @@ -330,6 +331,7 @@ public class SearchModule extends AbstractModule { registerBuiltinAggregations(); registerFetchSubPhases(plugins); registerShapes(); + searchRequestParsers = new SearchRequestParsers(queryParserRegistry, aggregatorParsers, getSuggesters()); } public List getNamedWriteables() { @@ -344,6 +346,10 @@ public class SearchModule extends AbstractModule { return queryParserRegistry; } + public SearchRequestParsers getSearchRequestParsers() { + return searchRequestParsers; + } + /** * Returns the {@link Highlighter} registry */ @@ -477,14 +483,9 @@ public class SearchModule extends AbstractModule { @Override protected void configure() { if (false == transportClient) { - /* - * Nothing is bound for transport client *but* SearchModule is still responsible for settings up the things like the - * NamedWriteableRegistry. - */ bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry); - bind(Suggesters.class).toInstance(getSuggesters()); + bind(SearchRequestParsers.class).toInstance(searchRequestParsers); configureSearch(); - bind(AggregatorParsers.class).toInstance(aggregatorParsers); } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java b/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java new file mode 100644 index 00000000000..911cc03fa84 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java @@ -0,0 +1,63 @@ +/* + * 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; + +import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.indices.query.IndicesQueriesRegistry; +import org.elasticsearch.search.aggregations.AggregatorParsers; +import org.elasticsearch.search.suggest.Suggesters; + +/** + * A container for all parsers used to parse + * {@link org.elasticsearch.action.search.SearchRequest} objects from a rest request. + */ +public class SearchRequestParsers { + // TODO: this class should be renamed to SearchRequestParser, and all the parse + // methods split across RestSearchAction and SearchSourceBuilder should be moved here + + // TODO: IndicesQueriesRegistry should be removed and just have the map of query parsers here + /** + * Query parsers that may be used in search requests. + * @see org.elasticsearch.index.query.QueryParseContext + * @see org.elasticsearch.search.builder.SearchSourceBuilder#fromXContent(QueryParseContext, AggregatorParsers, Suggesters) + */ + public final IndicesQueriesRegistry queryParsers; + + // TODO: AggregatorParsers should be removed and the underlying maps of agg + // and pipeline agg parsers should be here + /** + * Agg and pipeline agg parsers that may be used in search requests. + * @see org.elasticsearch.search.builder.SearchSourceBuilder#fromXContent(QueryParseContext, AggregatorParsers, Suggesters) + */ + public final AggregatorParsers aggParsers; + + // TODO: Suggesters should be removed and the underlying map moved here + /** + * Suggesters that may be used in search requests. + * @see org.elasticsearch.search.builder.SearchSourceBuilder#fromXContent(QueryParseContext, AggregatorParsers, Suggesters) + */ + public final Suggesters suggesters; + + public SearchRequestParsers(IndicesQueriesRegistry queryParsers, AggregatorParsers aggParsers, Suggesters suggesters) { + this.queryParsers = queryParsers; + this.aggParsers = aggParsers; + this.suggesters = suggesters; + } +} diff --git a/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java b/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java index 2eab8674bdd..3c9acb4104b 100644 --- a/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.index.query.QueryParser; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.search.RestMultiSearchAction; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.StreamsUtils; import org.elasticsearch.test.rest.FakeRestRequest; @@ -167,13 +168,13 @@ public class MultiSearchRequestTests extends ESTestCase { private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException { byte[] data = StreamsUtils.copyToBytesFromClasspath(sample); RestRequest restRequest = new FakeRestRequest.Builder().withContent(new BytesArray(data)).build(); - return RestMultiSearchAction.parseRequest(restRequest, true, registry(), ParseFieldMatcher.EMPTY, null, null); + return RestMultiSearchAction.parseRequest(restRequest, true, parsers(), ParseFieldMatcher.EMPTY); } - private IndicesQueriesRegistry registry() { + private SearchRequestParsers parsers() { IndicesQueriesRegistry registry = new IndicesQueriesRegistry(); QueryParser parser = MatchAllQueryBuilder::fromXContent; registry.register(parser, MatchAllQueryBuilder.NAME); - return registry; + return new SearchRequestParsers(registry, null, null); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java index f2b16c3e3ee..44f1adccc8b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -60,7 +61,7 @@ public class AggregationCollectorTests extends ESSingleNodeTestCase { } private boolean needsScores(IndexService index, String agg) throws IOException { - AggregatorParsers parser = getInstanceFromNode(AggregatorParsers.class); + AggregatorParsers parser = getInstanceFromNode(SearchRequestParsers.class).aggParsers; IndicesQueriesRegistry queriesRegistry = getInstanceFromNode(IndicesQueriesRegistry.class); XContentParser aggParser = JsonXContent.jsonXContent.createParser(agg); QueryParseContext parseContext = new QueryParseContext(queriesRegistry, aggParser, ParseFieldMatcher.STRICT); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index c3581fb6622..a7476381b8e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.IndicesModule; @@ -144,7 +145,7 @@ public class AggregatorParsingTests extends ESTestCase { bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry); } }).createInjector(); - aggParsers = injector.getInstance(AggregatorParsers.class); + aggParsers = injector.getInstance(SearchRequestParsers.class).aggParsers; // create some random type with some default field, those types will // stick around for all of the subclasses currentTypes = new String[randomIntBetween(0, 5)]; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index 076f6c5fb66..b9c0e5f09c1 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -42,6 +42,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.IndicesModule; @@ -106,7 +107,7 @@ public abstract class BaseAggregationTestCase SearchSourceBuilder.fromXContent(createParseContext(parser), aggParsers, suggesters)); + () -> SearchSourceBuilder.fromXContent(createParseContext(parser), + searchRequestParsers.aggParsers, searchRequestParsers.suggesters)); assertThat(e, hasToString(containsString("unit is missing or unrecognized"))); } } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index 42cd3987d47..b676536ba4b 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -43,6 +43,7 @@ import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestStatusToXContentListener; import org.elasticsearch.script.ScriptService; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; @@ -81,17 +82,12 @@ public class RestSearchTemplateAction extends BaseRestHandler { }, new ParseField("inline", "template"), ObjectParser.ValueType.OBJECT_OR_STRING); } - private final IndicesQueriesRegistry queryRegistry; - private final AggregatorParsers aggParsers; - private final Suggesters suggesters; + private final SearchRequestParsers searchRequestParsers; @Inject - public RestSearchTemplateAction(Settings settings, RestController controller, IndicesQueriesRegistry queryRegistry, - AggregatorParsers aggregatorParsers, Suggesters suggesters) { + public RestSearchTemplateAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) { super(settings); - this.queryRegistry = queryRegistry; - this.aggParsers = aggregatorParsers; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; controller.registerHandler(GET, "/_search/template", this); controller.registerHandler(POST, "/_search/template", this); @@ -109,7 +105,7 @@ public class RestSearchTemplateAction extends BaseRestHandler { // Creates the search request with all required params SearchRequest searchRequest = new SearchRequest(); - RestSearchAction.parseSearchRequest(searchRequest, queryRegistry, request, parseFieldMatcher, aggParsers, suggesters, null); + RestSearchAction.parseSearchRequest(searchRequest, request, searchRequestParsers, parseFieldMatcher, null); // Creates the search template request SearchTemplateRequest searchTemplateRequest = parse(RestActions.getRestContent(request)); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java index ded396deb12..473e287c9a2 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java @@ -36,6 +36,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.suggest.Suggesters; @@ -51,22 +52,17 @@ public class TransportSearchTemplateAction extends HandledTransportAction() { diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java index 0bd8b15bfb7..44914e140b1 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.query.IndicesQueriesRegistry; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -54,18 +55,17 @@ public class TransportMultiPercolateAction extends HandledTransportAction listener) { SearchRequest searchRequest; try { - searchRequest = createSearchRequest(request, docSource, queryRegistry, aggParsers, parseFieldMatcher); + searchRequest = createSearchRequest(request, docSource, searchRequestParsers.queryParsers, + searchRequestParsers.aggParsers, parseFieldMatcher); } catch (IOException e) { listener.onFailure(e); return; diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java index ef14f6fa66b..faa2607ce20 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java @@ -32,6 +32,7 @@ import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.tasks.LoggingTaskListener; @@ -46,19 +47,14 @@ public abstract class AbstractBaseReindexRestHandler< A extends GenericAction > extends BaseRestHandler { - protected final IndicesQueriesRegistry indicesQueriesRegistry; - protected final AggregatorParsers aggParsers; - protected final Suggesters suggesters; + protected final SearchRequestParsers searchRequestParsers; private final ClusterService clusterService; private final A action; - protected AbstractBaseReindexRestHandler(Settings settings, IndicesQueriesRegistry indicesQueriesRegistry, - AggregatorParsers aggParsers, Suggesters suggesters, + protected AbstractBaseReindexRestHandler(Settings settings, SearchRequestParsers searchRequestParsers, ClusterService clusterService, A action) { super(settings); - this.indicesQueriesRegistry = indicesQueriesRegistry; - this.aggParsers = aggParsers; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; this.clusterService = clusterService; this.action = action; } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java index 41f103698d6..3598c02abe5 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java @@ -33,6 +33,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.support.RestActions; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; @@ -49,10 +50,9 @@ public abstract class AbstractBulkByQueryRestHandler< Request extends AbstractBulkByScrollRequest, A extends GenericAction> extends AbstractBaseReindexRestHandler { - protected AbstractBulkByQueryRestHandler(Settings settings, IndicesQueriesRegistry indicesQueriesRegistry, - AggregatorParsers aggParsers, Suggesters suggesters, ClusterService clusterService, - A action) { - super(settings, indicesQueriesRegistry, aggParsers, suggesters, clusterService, action); + protected AbstractBulkByQueryRestHandler(Settings settings, SearchRequestParsers searchRequestParsers, + ClusterService clusterService, A action) { + super(settings, searchRequestParsers, clusterService, action); } protected void parseInternalRequest(Request internal, RestRequest restRequest, @@ -111,7 +111,6 @@ public abstract class AbstractBulkByQueryRestHandler< } } - RestSearchAction.parseSearchRequest(searchRequest, indicesQueriesRegistry, restRequest, parseFieldMatcher, aggParsers, - suggesters, content); + RestSearchAction.parseSearchRequest(searchRequest, restRequest, searchRequestParsers, parseFieldMatcher, content); } } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java index 704bcf2dbaf..92a96a880eb 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java @@ -29,6 +29,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; @@ -43,9 +44,8 @@ public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler