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.
This commit is contained in:
Ryan Ernst 2016-08-15 21:21:11 -07:00
parent 5ba06b6487
commit 7fde410586
23 changed files with 191 additions and 146 deletions

View File

@ -347,7 +347,7 @@ public class Node implements Closeable {
client = new NodeClient(settings, threadPool); client = new NodeClient(settings, threadPool);
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream() Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
.flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService, .flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService,
scriptModule.getScriptService()).stream()) scriptModule.getScriptService(), searchModule.getSearchRequestParsers()).stream())
.collect(Collectors.toList()); .collect(Collectors.toList());
modules.add(b -> { modules.add(b -> {
b.bind(PluginsService.class).toInstance(pluginsService); b.bind(PluginsService.class).toInstance(pluginsService);

View File

@ -39,6 +39,7 @@ import org.elasticsearch.index.IndexModule;
import org.elasticsearch.indices.analysis.AnalysisModule; import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService; 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 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 resourceWatcherService A service to watch for changes to node local files
* @param scriptService A service to allow running scripts on the local node * @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<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService) { ResourceWatcherService resourceWatcherService, ScriptService scriptService,
SearchRequestParsers searchRequestParsers) {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -40,6 +40,7 @@ import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestToXContentListener; import org.elasticsearch.rest.action.support.RestToXContentListener;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -59,16 +60,12 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestMultiSearchAction extends BaseRestHandler { public class RestMultiSearchAction extends BaseRestHandler {
private final boolean allowExplicitIndex; private final boolean allowExplicitIndex;
private final IndicesQueriesRegistry indicesQueriesRegistry; private final SearchRequestParsers searchRequestParsers;
private final AggregatorParsers aggParsers;
private final Suggesters suggesters;
@Inject @Inject
public RestMultiSearchAction(Settings settings, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry, public RestMultiSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
AggregatorParsers aggParsers, Suggesters suggesters) {
super(settings); super(settings);
this.aggParsers = aggParsers; this.searchRequestParsers = searchRequestParsers;
this.suggesters = suggesters;
controller.registerHandler(GET, "/_msearch", this); controller.registerHandler(GET, "/_msearch", this);
controller.registerHandler(POST, "/_msearch", this); controller.registerHandler(POST, "/_msearch", this);
@ -78,13 +75,11 @@ public class RestMultiSearchAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/{type}/_msearch", this); controller.registerHandler(POST, "/{index}/{type}/_msearch", this);
this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings);
this.indicesQueriesRegistry = indicesQueriesRegistry;
} }
@Override @Override
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) throws Exception { public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) throws Exception {
MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, indicesQueriesRegistry, parseFieldMatcher, MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, searchRequestParsers, parseFieldMatcher);
aggParsers, suggesters);
client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel)); 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} * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
*/ */
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex, public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex,
IndicesQueriesRegistry queriesRegistry, ParseFieldMatcher parseFieldMatcher, SearchRequestParsers searchRequestParsers,
AggregatorParsers aggParsers, Suggesters suggesters) throws IOException { ParseFieldMatcher parseFieldMatcher) throws IOException {
MultiSearchRequest multiRequest = new MultiSearchRequest(); MultiSearchRequest multiRequest = new MultiSearchRequest();
if (restRequest.hasParam("max_concurrent_searches")) { if (restRequest.hasParam("max_concurrent_searches")) {
@ -102,8 +97,10 @@ public class RestMultiSearchAction extends BaseRestHandler {
parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, bytes) -> { parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, bytes) -> {
try (XContentParser requestParser = XContentFactory.xContent(bytes).createParser(bytes)) { try (XContentParser requestParser = XContentFactory.xContent(bytes).createParser(bytes)) {
final QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry, requestParser, parseFieldMatcher); final QueryParseContext queryParseContext = new QueryParseContext(searchRequestParsers.queryParsers,
searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext, aggParsers, suggesters)); requestParser, parseFieldMatcher);
searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext,
searchRequestParsers.aggParsers, searchRequestParsers.suggesters));
multiRequest.add(searchRequest); multiRequest.add(searchRequest);
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("Exception when parsing search request", e); throw new ElasticsearchParseException("Exception when parsing search request", e);

View File

@ -41,6 +41,7 @@ import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestStatusToXContentListener; import org.elasticsearch.rest.action.support.RestStatusToXContentListener;
import org.elasticsearch.search.Scroll; import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
@ -63,17 +64,12 @@ import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion;
*/ */
public class RestSearchAction extends BaseRestHandler { public class RestSearchAction extends BaseRestHandler {
private final IndicesQueriesRegistry queryRegistry; private final SearchRequestParsers searchRequestParsers;
private final AggregatorParsers aggParsers;
private final Suggesters suggesters;
@Inject @Inject
public RestSearchAction(Settings settings, RestController controller, IndicesQueriesRegistry queryRegistry, public RestSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
AggregatorParsers aggParsers, Suggesters suggesters) {
super(settings); super(settings);
this.queryRegistry = queryRegistry; this.searchRequestParsers = searchRequestParsers;
this.aggParsers = aggParsers;
this.suggesters = suggesters;
controller.registerHandler(GET, "/_search", this); controller.registerHandler(GET, "/_search", this);
controller.registerHandler(POST, "/_search", this); controller.registerHandler(POST, "/_search", this);
controller.registerHandler(GET, "/{index}/_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 { public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) throws IOException {
SearchRequest searchRequest = new SearchRequest(); SearchRequest searchRequest = new SearchRequest();
BytesReference restContent = RestActions.hasBodyContent(request) ? RestActions.getRestContent(request) : null; 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)); client.search(searchRequest, new RestStatusToXContentListener<>(channel));
} }
@ -99,9 +95,8 @@ public class RestSearchAction extends BaseRestHandler {
* content is read from the request using * content is read from the request using
* RestAction.hasBodyContent. * RestAction.hasBodyContent.
*/ */
public static void parseSearchRequest(SearchRequest searchRequest, IndicesQueriesRegistry indicesQueriesRegistry, RestRequest request, public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, SearchRequestParsers searchRequestParsers,
ParseFieldMatcher parseFieldMatcher, AggregatorParsers aggParsers, Suggesters suggesters, BytesReference restContent) ParseFieldMatcher parseFieldMatcher, BytesReference restContent) throws IOException {
throws IOException {
if (searchRequest.source() == null) { if (searchRequest.source() == null) {
searchRequest.source(new SearchSourceBuilder()); searchRequest.source(new SearchSourceBuilder());
@ -109,8 +104,8 @@ public class RestSearchAction extends BaseRestHandler {
searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index"))); searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
if (restContent != null) { if (restContent != null) {
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher);
searchRequest.source().parseXContent(context, aggParsers, suggesters); searchRequest.source().parseXContent(context, searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
} }
} }

View File

@ -41,6 +41,7 @@ import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestBuilderListener; import org.elasticsearch.rest.action.support.RestBuilderListener;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder; import org.elasticsearch.search.suggest.SuggestBuilder;
@ -57,15 +58,13 @@ import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastSh
*/ */
public class RestSuggestAction extends BaseRestHandler { public class RestSuggestAction extends BaseRestHandler {
private final IndicesQueriesRegistry queryRegistry; private final SearchRequestParsers searchRequestParsers;
private final Suggesters suggesters;
@Inject @Inject
public RestSuggestAction(Settings settings, RestController controller, public RestSuggestAction(Settings settings, RestController controller,
IndicesQueriesRegistry queryRegistry, Suggesters suggesters) { SearchRequestParsers searchRequestParsers) {
super(settings); super(settings);
this.queryRegistry = queryRegistry; this.searchRequestParsers = searchRequestParsers;
this.suggesters = suggesters;
controller.registerHandler(POST, "/_suggest", this); controller.registerHandler(POST, "/_suggest", this);
controller.registerHandler(GET, "/_suggest", this); controller.registerHandler(GET, "/_suggest", this);
controller.registerHandler(POST, "/{index}/_suggest", this); controller.registerHandler(POST, "/{index}/_suggest", this);
@ -79,8 +78,8 @@ public class RestSuggestAction extends BaseRestHandler {
if (RestActions.hasBodyContent(request)) { if (RestActions.hasBodyContent(request)) {
final BytesReference sourceBytes = RestActions.getRestContent(request); final BytesReference sourceBytes = RestActions.getRestContent(request);
try (XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes)) { try (XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes)) {
final QueryParseContext context = new QueryParseContext(queryRegistry, parser, parseFieldMatcher); final QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher);
searchRequest.source().suggest(SuggestBuilder.fromXContent(context, suggesters)); searchRequest.source().suggest(SuggestBuilder.fromXContent(context, searchRequestParsers.suggesters));
} }
} else { } else {
throw new IllegalArgumentException("no content or source provided to execute suggestion"); throw new IllegalArgumentException("no content or source provided to execute suggestion");

View File

@ -309,6 +309,7 @@ public class SearchModule extends AbstractModule {
private final Settings settings; private final Settings settings;
private final List<Entry> namedWriteables = new ArrayList<>(); private final List<Entry> namedWriteables = new ArrayList<>();
private final SearchRequestParsers searchRequestParsers;
public static final Setting<Integer> INDICES_MAX_CLAUSE_COUNT_SETTING = Setting.intSetting("indices.query.bool.max_clause_count", public static final Setting<Integer> INDICES_MAX_CLAUSE_COUNT_SETTING = Setting.intSetting("indices.query.bool.max_clause_count",
1024, 1, Integer.MAX_VALUE, Setting.Property.NodeScope); 1024, 1, Integer.MAX_VALUE, Setting.Property.NodeScope);
@ -330,6 +331,7 @@ public class SearchModule extends AbstractModule {
registerBuiltinAggregations(); registerBuiltinAggregations();
registerFetchSubPhases(plugins); registerFetchSubPhases(plugins);
registerShapes(); registerShapes();
searchRequestParsers = new SearchRequestParsers(queryParserRegistry, aggregatorParsers, getSuggesters());
} }
public List<Entry> getNamedWriteables() { public List<Entry> getNamedWriteables() {
@ -344,6 +346,10 @@ public class SearchModule extends AbstractModule {
return queryParserRegistry; return queryParserRegistry;
} }
public SearchRequestParsers getSearchRequestParsers() {
return searchRequestParsers;
}
/** /**
* Returns the {@link Highlighter} registry * Returns the {@link Highlighter} registry
*/ */
@ -477,14 +483,9 @@ public class SearchModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
if (false == transportClient) { 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(IndicesQueriesRegistry.class).toInstance(queryParserRegistry);
bind(Suggesters.class).toInstance(getSuggesters()); bind(SearchRequestParsers.class).toInstance(searchRequestParsers);
configureSearch(); configureSearch();
bind(AggregatorParsers.class).toInstance(aggregatorParsers);
} }
} }

View File

@ -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;
}
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestMultiSearchAction; import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.StreamsUtils; import org.elasticsearch.test.StreamsUtils;
import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.FakeRestRequest;
@ -167,13 +168,13 @@ public class MultiSearchRequestTests extends ESTestCase {
private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException { private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample); byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
RestRequest restRequest = new FakeRestRequest.Builder().withContent(new BytesArray(data)).build(); 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(); IndicesQueriesRegistry registry = new IndicesQueriesRegistry();
QueryParser<MatchAllQueryBuilder> parser = MatchAllQueryBuilder::fromXContent; QueryParser<MatchAllQueryBuilder> parser = MatchAllQueryBuilder::fromXContent;
registry.register(parser, MatchAllQueryBuilder.NAME); registry.register(parser, MatchAllQueryBuilder.NAME);
return registry; return new SearchRequestParsers(registry, null, null);
} }
} }

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
@ -60,7 +61,7 @@ public class AggregationCollectorTests extends ESSingleNodeTestCase {
} }
private boolean needsScores(IndexService index, String agg) throws IOException { 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); IndicesQueriesRegistry queriesRegistry = getInstanceFromNode(IndicesQueriesRegistry.class);
XContentParser aggParser = JsonXContent.jsonXContent.createParser(agg); XContentParser aggParser = JsonXContent.jsonXContent.createParser(agg);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, aggParser, ParseFieldMatcher.STRICT); QueryParseContext parseContext = new QueryParseContext(queriesRegistry, aggParser, ParseFieldMatcher.STRICT);

View File

@ -38,6 +38,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.IndicesModule;
@ -144,7 +145,7 @@ public class AggregatorParsingTests extends ESTestCase {
bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry); bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);
} }
}).createInjector(); }).createInjector();
aggParsers = injector.getInstance(AggregatorParsers.class); aggParsers = injector.getInstance(SearchRequestParsers.class).aggParsers;
// create some random type with some default field, those types will // create some random type with some default field, those types will
// stick around for all of the subclasses // stick around for all of the subclasses
currentTypes = new String[randomIntBetween(0, 5)]; currentTypes = new String[randomIntBetween(0, 5)];

View File

@ -42,6 +42,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.IndicesModule;
@ -106,7 +107,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_"); index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
injector = buildInjector(index); injector = buildInjector(index);
namedWriteableRegistry = injector.getInstance(NamedWriteableRegistry.class); namedWriteableRegistry = injector.getInstance(NamedWriteableRegistry.class);
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 //create some random type with some default field, those types will stick around for all of the subclasses
currentTypes = new String[randomIntBetween(0, 5)]; currentTypes = new String[randomIntBetween(0, 5)];
for (int i = 0; i < currentTypes.length; i++) { for (int i = 0; i < currentTypes.length; i++) {

View File

@ -35,6 +35,7 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
@ -77,7 +78,7 @@ public abstract class BasePipelineAggregationTestCase<AF extends AbstractPipelin
index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_"); index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
injector = BaseAggregationTestCase.buildInjector(index); injector = BaseAggregationTestCase.buildInjector(index);
namedWriteableRegistry = injector.getInstance(NamedWriteableRegistry.class); namedWriteableRegistry = injector.getInstance(NamedWriteableRegistry.class);
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 //create some random type with some default field, those types will stick around for all of the subclasses
currentTypes = new String[randomIntBetween(0, 5)]; currentTypes = new String[randomIntBetween(0, 5)];
for (int i = 0; i < currentTypes.length; i++) { for (int i = 0; i < currentTypes.length; i++) {

View File

@ -58,6 +58,7 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
@ -99,14 +100,10 @@ public class SearchSourceBuilderTests extends ESTestCase {
private static NamedWriteableRegistry namedWriteableRegistry; private static NamedWriteableRegistry namedWriteableRegistry;
private static IndicesQueriesRegistry indicesQueriesRegistry; private static SearchRequestParsers searchRequestParsers;
private static Index index; private static Index index;
private static AggregatorParsers aggParsers;
private static Suggesters suggesters;
private static String[] currentTypes; private static String[] currentTypes;
private static ParseFieldMatcher parseFieldMatcher; private static ParseFieldMatcher parseFieldMatcher;
@ -165,8 +162,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
} }
} }
).createInjector(); ).createInjector();
aggParsers = injector.getInstance(AggregatorParsers.class); searchRequestParsers = injector.getInstance(SearchRequestParsers.class);
suggesters = injector.getInstance(Suggesters.class);
// create some random type with some default field, those types will // create some random type with some default field, those types will
// stick around for all of the subclasses // stick around for all of the subclasses
currentTypes = new String[randomIntBetween(0, 5)]; currentTypes = new String[randomIntBetween(0, 5)];
@ -174,7 +170,6 @@ public class SearchSourceBuilderTests extends ESTestCase {
String type = randomAsciiOfLengthBetween(1, 10); String type = randomAsciiOfLengthBetween(1, 10);
currentTypes[i] = type; currentTypes[i] = type;
} }
indicesQueriesRegistry = injector.getInstance(IndicesQueriesRegistry.class);
parseFieldMatcher = ParseFieldMatcher.STRICT; parseFieldMatcher = ParseFieldMatcher.STRICT;
} }
@ -184,8 +179,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
terminate(injector.getInstance(ThreadPool.class)); terminate(injector.getInstance(ThreadPool.class));
injector = null; injector = null;
index = null; index = null;
aggParsers = null; searchRequestParsers = null;
suggesters = null;
currentTypes = null; currentTypes = null;
namedWriteableRegistry = null; namedWriteableRegistry = null;
} }
@ -428,19 +422,20 @@ public class SearchSourceBuilderTests extends ESTestCase {
private static void assertParseSearchSource(SearchSourceBuilder testBuilder, BytesReference searchSourceAsBytes, ParseFieldMatcher pfm) private static void assertParseSearchSource(SearchSourceBuilder testBuilder, BytesReference searchSourceAsBytes, ParseFieldMatcher pfm)
throws IOException { throws IOException {
XContentParser parser = XContentFactory.xContent(searchSourceAsBytes).createParser(searchSourceAsBytes); XContentParser parser = XContentFactory.xContent(searchSourceAsBytes).createParser(searchSourceAsBytes);
QueryParseContext parseContext = new QueryParseContext(indicesQueriesRegistry, parser, pfm); QueryParseContext parseContext = new QueryParseContext(searchRequestParsers.queryParsers, parser, pfm);
if (randomBoolean()) { if (randomBoolean()) {
parser.nextToken(); // sometimes we move it on the START_OBJECT to parser.nextToken(); // sometimes we move it on the START_OBJECT to
// test the embedded case // test the embedded case
} }
SearchSourceBuilder newBuilder = SearchSourceBuilder.fromXContent(parseContext, aggParsers, suggesters); SearchSourceBuilder newBuilder = SearchSourceBuilder.fromXContent(parseContext, searchRequestParsers.aggParsers,
searchRequestParsers.suggesters);
assertNull(parser.nextToken()); assertNull(parser.nextToken());
assertEquals(testBuilder, newBuilder); assertEquals(testBuilder, newBuilder);
assertEquals(testBuilder.hashCode(), newBuilder.hashCode()); assertEquals(testBuilder.hashCode(), newBuilder.hashCode());
} }
private static QueryParseContext createParseContext(XContentParser parser) { private static QueryParseContext createParseContext(XContentParser parser) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher);
return context; return context;
} }
@ -499,7 +494,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
String restContent = " { \"_source\": { \"includes\": \"include\", \"excludes\": \"*.field2\"}}"; String restContent = " { \"_source\": { \"includes\": \"include\", \"excludes\": \"*.field2\"}}";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
aggParsers, suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertArrayEquals(new String[]{"*.field2"}, searchSourceBuilder.fetchSource().excludes()); assertArrayEquals(new String[]{"*.field2"}, searchSourceBuilder.fetchSource().excludes());
assertArrayEquals(new String[]{"include"}, searchSourceBuilder.fetchSource().includes()); assertArrayEquals(new String[]{"include"}, searchSourceBuilder.fetchSource().includes());
} }
@ -508,7 +503,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
String restContent = " { \"_source\": false}"; String restContent = " { \"_source\": false}";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
aggParsers, suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertArrayEquals(new String[]{}, searchSourceBuilder.fetchSource().excludes()); assertArrayEquals(new String[]{}, searchSourceBuilder.fetchSource().excludes());
assertArrayEquals(new String[]{}, searchSourceBuilder.fetchSource().includes()); assertArrayEquals(new String[]{}, searchSourceBuilder.fetchSource().includes());
assertFalse(searchSourceBuilder.fetchSource().fetchSource()); assertFalse(searchSourceBuilder.fetchSource().fetchSource());
@ -521,7 +516,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
String restContent = " { \"sort\": \"foo\"}"; String restContent = " { \"sort\": \"foo\"}";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
aggParsers, suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertEquals(1, searchSourceBuilder.sorts().size()); assertEquals(1, searchSourceBuilder.sorts().size());
assertEquals(new FieldSortBuilder("foo"), searchSourceBuilder.sorts().get(0)); assertEquals(new FieldSortBuilder("foo"), searchSourceBuilder.sorts().get(0));
} }
@ -537,7 +532,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
" ]}"; " ]}";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
aggParsers, suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertEquals(5, searchSourceBuilder.sorts().size()); assertEquals(5, searchSourceBuilder.sorts().size());
assertEquals(new FieldSortBuilder("post_date"), searchSourceBuilder.sorts().get(0)); assertEquals(new FieldSortBuilder("post_date"), searchSourceBuilder.sorts().get(0));
assertEquals(new FieldSortBuilder("user"), searchSourceBuilder.sorts().get(1)); assertEquals(new FieldSortBuilder("user"), searchSourceBuilder.sorts().get(1));
@ -560,8 +555,8 @@ public class SearchSourceBuilderTests extends ESTestCase {
" }\n" + " }\n" +
"}\n"; "}\n";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), aggParsers, SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertEquals(1, searchSourceBuilder.aggregations().count()); assertEquals(1, searchSourceBuilder.aggregations().count());
} }
} }
@ -576,8 +571,8 @@ public class SearchSourceBuilderTests extends ESTestCase {
" }\n" + " }\n" +
"}\n"; "}\n";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), aggParsers, SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertEquals(1, searchSourceBuilder.aggregations().count()); assertEquals(1, searchSourceBuilder.aggregations().count());
} }
} }
@ -603,7 +598,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
"}\n"; "}\n";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
aggParsers, suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertEquals(1, searchSourceBuilder.rescores().size()); assertEquals(1, searchSourceBuilder.rescores().size());
assertEquals(new QueryRescorerBuilder(QueryBuilders.matchQuery("content", "baz")).windowSize(50), assertEquals(new QueryRescorerBuilder(QueryBuilders.matchQuery("content", "baz")).windowSize(50),
searchSourceBuilder.rescores().get(0)); searchSourceBuilder.rescores().get(0));
@ -626,7 +621,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
"}\n"; "}\n";
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser), SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
aggParsers, suggesters); searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertEquals(1, searchSourceBuilder.rescores().size()); assertEquals(1, searchSourceBuilder.rescores().size());
assertEquals(new QueryRescorerBuilder(QueryBuilders.matchQuery("content", "baz")).windowSize(50), assertEquals(new QueryRescorerBuilder(QueryBuilders.matchQuery("content", "baz")).windowSize(50),
searchSourceBuilder.rescores().get(0)); searchSourceBuilder.rescores().get(0));
@ -638,7 +633,8 @@ public class SearchSourceBuilderTests extends ESTestCase {
final String timeout = randomTimeValue(); final String timeout = randomTimeValue();
final String query = "{ \"query\": { \"match_all\": {}}, \"timeout\": \"" + timeout + "\"}"; final String query = "{ \"query\": { \"match_all\": {}}, \"timeout\": \"" + timeout + "\"}";
try (XContentParser parser = XContentFactory.xContent(query).createParser(query)) { try (XContentParser parser = XContentFactory.xContent(query).createParser(query)) {
final SearchSourceBuilder builder = SearchSourceBuilder.fromXContent(createParseContext(parser), aggParsers, suggesters); final SearchSourceBuilder builder = SearchSourceBuilder.fromXContent(createParseContext(parser),
searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
assertThat(builder.timeout(), equalTo(TimeValue.parseTimeValue(timeout, null, "timeout"))); assertThat(builder.timeout(), equalTo(TimeValue.parseTimeValue(timeout, null, "timeout")));
} }
} }
@ -650,7 +646,8 @@ public class SearchSourceBuilderTests extends ESTestCase {
final ElasticsearchParseException e = final ElasticsearchParseException e =
expectThrows( expectThrows(
ElasticsearchParseException.class, ElasticsearchParseException.class,
() -> SearchSourceBuilder.fromXContent(createParseContext(parser), aggParsers, suggesters)); () -> SearchSourceBuilder.fromXContent(createParseContext(parser),
searchRequestParsers.aggParsers, searchRequestParsers.suggesters));
assertThat(e, hasToString(containsString("unit is missing or unrecognized"))); assertThat(e, hasToString(containsString("unit is missing or unrecognized")));
} }
} }

View File

@ -43,6 +43,7 @@ import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestStatusToXContentListener; import org.elasticsearch.rest.action.support.RestStatusToXContentListener;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -81,17 +82,12 @@ public class RestSearchTemplateAction extends BaseRestHandler {
}, new ParseField("inline", "template"), ObjectParser.ValueType.OBJECT_OR_STRING); }, new ParseField("inline", "template"), ObjectParser.ValueType.OBJECT_OR_STRING);
} }
private final IndicesQueriesRegistry queryRegistry; private final SearchRequestParsers searchRequestParsers;
private final AggregatorParsers aggParsers;
private final Suggesters suggesters;
@Inject @Inject
public RestSearchTemplateAction(Settings settings, RestController controller, IndicesQueriesRegistry queryRegistry, public RestSearchTemplateAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
AggregatorParsers aggregatorParsers, Suggesters suggesters) {
super(settings); super(settings);
this.queryRegistry = queryRegistry; this.searchRequestParsers = searchRequestParsers;
this.aggParsers = aggregatorParsers;
this.suggesters = suggesters;
controller.registerHandler(GET, "/_search/template", this); controller.registerHandler(GET, "/_search/template", this);
controller.registerHandler(POST, "/_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 // Creates the search request with all required params
SearchRequest searchRequest = new SearchRequest(); 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 // Creates the search template request
SearchTemplateRequest searchTemplateRequest = parse(RestActions.getRestContent(request)); SearchTemplateRequest searchTemplateRequest = parse(RestActions.getRestContent(request));

View File

@ -36,6 +36,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -51,22 +52,17 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
private final ScriptService scriptService; private final ScriptService scriptService;
private final TransportSearchAction searchAction; private final TransportSearchAction searchAction;
private final IndicesQueriesRegistry queryRegistry; private final SearchRequestParsers searchRequestParsers;
private final AggregatorParsers aggsParsers;
private final Suggesters suggesters;
@Inject @Inject
public TransportSearchTemplateAction(Settings settings, ThreadPool threadPool, TransportService transportService, public TransportSearchTemplateAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ActionFilters actionFilters, IndexNameExpressionResolver resolver, ActionFilters actionFilters, IndexNameExpressionResolver resolver,
ScriptService scriptService, ScriptService scriptService,
TransportSearchAction searchAction, IndicesQueriesRegistry indicesQueryRegistry, TransportSearchAction searchAction, SearchRequestParsers searchRequestParsers) {
AggregatorParsers aggregatorParsers, Suggesters suggesters) {
super(settings, SearchTemplateAction.NAME, threadPool, transportService, actionFilters, resolver, SearchTemplateRequest::new); super(settings, SearchTemplateAction.NAME, threadPool, transportService, actionFilters, resolver, SearchTemplateRequest::new);
this.scriptService = scriptService; this.scriptService = scriptService;
this.searchAction = searchAction; this.searchAction = searchAction;
this.queryRegistry = indicesQueryRegistry; this.searchRequestParsers = searchRequestParsers;
this.aggsParsers = aggregatorParsers;
this.suggesters = suggesters;
} }
@Override @Override
@ -89,7 +85,8 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) { try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) {
SearchSourceBuilder builder = SearchSourceBuilder.searchSource(); SearchSourceBuilder builder = SearchSourceBuilder.searchSource();
builder.parseXContent(new QueryParseContext(queryRegistry, parser, parseFieldMatcher), aggsParsers, suggesters); builder.parseXContent(new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher),
searchRequestParsers.aggParsers, searchRequestParsers.suggesters);
searchRequest.source(builder); searchRequest.source(builder);
searchAction.execute(searchRequest, new ActionListener<SearchResponse>() { searchAction.execute(searchRequest, new ActionListener<SearchResponse>() {

View File

@ -38,6 +38,7 @@ import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -54,18 +55,17 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
private final Client client; private final Client client;
private final ParseFieldMatcher parseFieldMatcher; private final ParseFieldMatcher parseFieldMatcher;
private final IndicesQueriesRegistry queryRegistry; private final SearchRequestParsers searchRequestParsers;
private final AggregatorParsers aggParsers;
@Inject @Inject
public TransportMultiPercolateAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters, public TransportMultiPercolateAction(Settings settings, ThreadPool threadPool, TransportService transportService,
IndexNameExpressionResolver indexNameExpressionResolver, Client client, IndicesQueriesRegistry queryRegistry, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
AggregatorParsers aggParsers) { Client client, SearchRequestParsers searchRequestParsers) {
super(settings, MultiPercolateAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, MultiPercolateRequest::new); super(settings, MultiPercolateAction.NAME, threadPool, transportService, actionFilters,
indexNameExpressionResolver, MultiPercolateRequest::new);
this.client = client; this.client = client;
this.aggParsers = aggParsers; this.searchRequestParsers = searchRequestParsers;
this.parseFieldMatcher = new ParseFieldMatcher(settings); this.parseFieldMatcher = new ParseFieldMatcher(settings);
this.queryRegistry = queryRegistry;
} }
@Override @Override
@ -159,7 +159,8 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
BytesReference docSource = getResponseSources.get(i); BytesReference docSource = getResponseSources.get(i);
try { try {
SearchRequest searchRequest = TransportPercolateAction.createSearchRequest( SearchRequest searchRequest = TransportPercolateAction.createSearchRequest(
percolateRequest, docSource, queryRegistry, aggParsers, parseFieldMatcher percolateRequest, docSource, searchRequestParsers.queryParsers,
searchRequestParsers.aggParsers, parseFieldMatcher
); );
multiSearchRequest.add(searchRequest); multiSearchRequest.add(searchRequest);
} catch (Exception e) { } catch (Exception e) {

View File

@ -47,6 +47,7 @@ import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
@ -62,18 +63,16 @@ public class TransportPercolateAction extends HandledTransportAction<PercolateRe
private final Client client; private final Client client;
private final ParseFieldMatcher parseFieldMatcher; private final ParseFieldMatcher parseFieldMatcher;
private final IndicesQueriesRegistry queryRegistry; private final SearchRequestParsers searchRequestParsers;
private final AggregatorParsers aggParsers;
@Inject @Inject
public TransportPercolateAction(Settings settings, ThreadPool threadPool, TransportService transportService, public TransportPercolateAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
Client client, IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers) { Client client, SearchRequestParsers searchRequestParsers) {
super(settings, PercolateAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, PercolateRequest::new); super(settings, PercolateAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, PercolateRequest::new);
this.client = client; this.client = client;
this.aggParsers = aggParsers; this.searchRequestParsers = searchRequestParsers;
this.parseFieldMatcher = new ParseFieldMatcher(settings); this.parseFieldMatcher = new ParseFieldMatcher(settings);
this.queryRegistry = indicesQueriesRegistry;
} }
@Override @Override
@ -102,7 +101,8 @@ public class TransportPercolateAction extends HandledTransportAction<PercolateRe
private void innerDoExecute(PercolateRequest request, BytesReference docSource, ActionListener<PercolateResponse> listener) { private void innerDoExecute(PercolateRequest request, BytesReference docSource, ActionListener<PercolateResponse> listener) {
SearchRequest searchRequest; SearchRequest searchRequest;
try { try {
searchRequest = createSearchRequest(request, docSource, queryRegistry, aggParsers, parseFieldMatcher); searchRequest = createSearchRequest(request, docSource, searchRequestParsers.queryParsers,
searchRequestParsers.aggParsers, parseFieldMatcher);
} catch (IOException e) { } catch (IOException e) {
listener.onFailure(e); listener.onFailure(e);
return; return;

View File

@ -32,6 +32,7 @@ import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
import org.elasticsearch.tasks.LoggingTaskListener; import org.elasticsearch.tasks.LoggingTaskListener;
@ -46,19 +47,14 @@ public abstract class AbstractBaseReindexRestHandler<
A extends GenericAction<Request, BulkIndexByScrollResponse> A extends GenericAction<Request, BulkIndexByScrollResponse>
> extends BaseRestHandler { > extends BaseRestHandler {
protected final IndicesQueriesRegistry indicesQueriesRegistry; protected final SearchRequestParsers searchRequestParsers;
protected final AggregatorParsers aggParsers;
protected final Suggesters suggesters;
private final ClusterService clusterService; private final ClusterService clusterService;
private final A action; private final A action;
protected AbstractBaseReindexRestHandler(Settings settings, IndicesQueriesRegistry indicesQueriesRegistry, protected AbstractBaseReindexRestHandler(Settings settings, SearchRequestParsers searchRequestParsers,
AggregatorParsers aggParsers, Suggesters suggesters,
ClusterService clusterService, A action) { ClusterService clusterService, A action) {
super(settings); super(settings);
this.indicesQueriesRegistry = indicesQueriesRegistry; this.searchRequestParsers = searchRequestParsers;
this.aggParsers = aggParsers;
this.suggesters = suggesters;
this.clusterService = clusterService; this.clusterService = clusterService;
this.action = action; this.action = action;
} }

View File

@ -33,6 +33,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -49,10 +50,9 @@ public abstract class AbstractBulkByQueryRestHandler<
Request extends AbstractBulkByScrollRequest<Request>, Request extends AbstractBulkByScrollRequest<Request>,
A extends GenericAction<Request, BulkIndexByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> { A extends GenericAction<Request, BulkIndexByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {
protected AbstractBulkByQueryRestHandler(Settings settings, IndicesQueriesRegistry indicesQueriesRegistry, protected AbstractBulkByQueryRestHandler(Settings settings, SearchRequestParsers searchRequestParsers,
AggregatorParsers aggParsers, Suggesters suggesters, ClusterService clusterService, ClusterService clusterService, A action) {
A action) { super(settings, searchRequestParsers, clusterService, action);
super(settings, indicesQueriesRegistry, aggParsers, suggesters, clusterService, action);
} }
protected void parseInternalRequest(Request internal, RestRequest restRequest, protected void parseInternalRequest(Request internal, RestRequest restRequest,
@ -111,7 +111,6 @@ public abstract class AbstractBulkByQueryRestHandler<
} }
} }
RestSearchAction.parseSearchRequest(searchRequest, indicesQueriesRegistry, restRequest, parseFieldMatcher, aggParsers, RestSearchAction.parseSearchRequest(searchRequest, restRequest, searchRequestParsers, parseFieldMatcher, content);
suggesters, content);
} }
} }

View File

@ -29,6 +29,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -43,9 +44,8 @@ public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler<Dele
@Inject @Inject
public RestDeleteByQueryAction(Settings settings, RestController controller, public RestDeleteByQueryAction(Settings settings, RestController controller,
IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers, Suggesters suggesters, SearchRequestParsers searchRequestParsers, ClusterService clusterService) {
ClusterService clusterService) { super(settings, searchRequestParsers, clusterService, DeleteByQueryAction.INSTANCE);
super(settings, indicesQueriesRegistry, aggParsers, suggesters, clusterService, DeleteByQueryAction.INSTANCE);
controller.registerHandler(POST, "/{index}/_delete_by_query", this); controller.registerHandler(POST, "/{index}/_delete_by_query", this);
controller.registerHandler(POST, "/{index}/{type}/_delete_by_query", this); controller.registerHandler(POST, "/{index}/{type}/_delete_by_query", this);
} }

View File

@ -47,6 +47,7 @@ import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -85,8 +86,8 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType()); XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
builder.map(source); builder.map(source);
try (XContentParser innerParser = parser.contentType().xContent().createParser(builder.bytes())) { try (XContentParser innerParser = parser.contentType().xContent().createParser(builder.bytes())) {
request.getSearchRequest().source().parseXContent(context.queryParseContext(innerParser), context.aggParsers, request.getSearchRequest().source().parseXContent(context.queryParseContext(innerParser),
context.suggesters); context.searchRequestParsers.aggParsers, context.searchRequestParsers.suggesters);
} }
}; };
@ -113,9 +114,8 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
@Inject @Inject
public RestReindexAction(Settings settings, RestController controller, public RestReindexAction(Settings settings, RestController controller,
IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers, Suggesters suggesters, SearchRequestParsers searchRequestParsers, ClusterService clusterService) {
ClusterService clusterService) { super(settings, searchRequestParsers, clusterService, ReindexAction.INSTANCE);
super(settings, indicesQueriesRegistry, aggParsers, suggesters, clusterService, ReindexAction.INSTANCE);
controller.registerHandler(POST, "/_reindex", this); controller.registerHandler(POST, "/_reindex", this);
} }
@ -131,7 +131,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
protected ReindexRequest buildRequest(RestRequest request) throws IOException { protected ReindexRequest buildRequest(RestRequest request) throws IOException {
ReindexRequest internal = new ReindexRequest(new SearchRequest(), new IndexRequest()); ReindexRequest internal = new ReindexRequest(new SearchRequest(), new IndexRequest());
try (XContentParser xcontent = XContentFactory.xContent(request.content()).createParser(request.content())) { try (XContentParser xcontent = XContentFactory.xContent(request.content()).createParser(request.content())) {
PARSER.parse(xcontent, internal, new ReindexParseContext(indicesQueriesRegistry, aggParsers, suggesters, parseFieldMatcher)); PARSER.parse(xcontent, internal, new ReindexParseContext(searchRequestParsers, parseFieldMatcher));
} }
return internal; return internal;
} }
@ -225,21 +225,16 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
} }
static class ReindexParseContext implements ParseFieldMatcherSupplier { static class ReindexParseContext implements ParseFieldMatcherSupplier {
private final IndicesQueriesRegistry indicesQueryRegistry; private final SearchRequestParsers searchRequestParsers;
private final ParseFieldMatcher parseFieldMatcher; private final ParseFieldMatcher parseFieldMatcher;
private final AggregatorParsers aggParsers;
private final Suggesters suggesters;
public ReindexParseContext(IndicesQueriesRegistry indicesQueryRegistry, AggregatorParsers aggParsers, ReindexParseContext(SearchRequestParsers searchRequestParsers, ParseFieldMatcher parseFieldMatcher) {
Suggesters suggesters, ParseFieldMatcher parseFieldMatcher) { this.searchRequestParsers = searchRequestParsers;
this.indicesQueryRegistry = indicesQueryRegistry;
this.aggParsers = aggParsers;
this.suggesters = suggesters;
this.parseFieldMatcher = parseFieldMatcher; this.parseFieldMatcher = parseFieldMatcher;
} }
public QueryParseContext queryParseContext(XContentParser parser) { QueryParseContext queryParseContext(XContentParser parser) {
return new QueryParseContext(indicesQueryRegistry, parser, parseFieldMatcher); return new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher);
} }
@Override @Override

View File

@ -32,6 +32,7 @@ import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.search.suggest.Suggesters;
@ -48,9 +49,8 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
@Inject @Inject
public RestUpdateByQueryAction(Settings settings, RestController controller, public RestUpdateByQueryAction(Settings settings, RestController controller,
IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers, Suggesters suggesters, SearchRequestParsers searchRequestParsers, ClusterService clusterService) {
ClusterService clusterService) { super(settings, searchRequestParsers, clusterService, UpdateByQueryAction.INSTANCE);
super(settings, indicesQueriesRegistry, aggParsers, suggesters, clusterService, UpdateByQueryAction.INSTANCE);
controller.registerHandler(POST, "/{index}/_update_by_query", this); controller.registerHandler(POST, "/{index}/_update_by_query", this);
controller.registerHandler(POST, "/{index}/{type}/_update_by_query", this); controller.registerHandler(POST, "/{index}/{type}/_update_by_query", this);
} }

View File

@ -29,6 +29,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.reindex.RestReindexAction.ReindexParseContext; import org.elasticsearch.index.reindex.RestReindexAction.ReindexParseContext;
import org.elasticsearch.index.reindex.remote.RemoteInfo; import org.elasticsearch.index.reindex.remote.RemoteInfo;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import java.io.IOException; import java.io.IOException;
@ -109,8 +110,8 @@ public class RestReindexActionTests extends ESTestCase {
} }
try (XContentParser p = JsonXContent.jsonXContent.createParser(request)) { try (XContentParser p = JsonXContent.jsonXContent.createParser(request)) {
ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest()); ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
RestReindexAction.PARSER.parse(p, r, SearchRequestParsers searchParsers = new SearchRequestParsers(new IndicesQueriesRegistry(), null, null);
new ReindexParseContext(new IndicesQueriesRegistry(), null, null, ParseFieldMatcher.STRICT)); RestReindexAction.PARSER.parse(p, r, new ReindexParseContext(searchParsers, ParseFieldMatcher.STRICT));
assertEquals("localhost", r.getRemoteInfo().getHost()); assertEquals("localhost", r.getRemoteInfo().getHost());
assertArrayEquals(new String[] {"source"}, r.getSearchRequest().indices()); assertArrayEquals(new String[] {"source"}, r.getSearchRequest().indices());
} }