Replace IndicesQueriesRegistry (#22289)

* Switch query parsing to namedObject
* Remove IndicesQueriesRegistry
This commit is contained in:
Nik Everett 2016-12-21 09:05:14 -05:00 committed by GitHub
parent 80f8dfe852
commit 567c65b0d5
69 changed files with 282 additions and 457 deletions

View File

@ -48,7 +48,6 @@ import org.elasticsearch.indices.IndicesQueryCache;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.ThreadPool;
@ -327,7 +326,6 @@ public final class IndexModule {
BigArrays bigArrays,
ThreadPool threadPool,
ScriptService scriptService,
IndicesQueriesRegistry indicesQueriesRegistry,
ClusterService clusterService,
Client client,
IndicesQueryCache indicesQueryCache,
@ -366,7 +364,7 @@ public final class IndexModule {
}
return new IndexService(indexSettings, environment, xContentRegistry, new SimilarityService(indexSettings, similarities),
shardStoreDeleter, analysisRegistry, engineFactory.get(), circuitBreakerService, bigArrays, threadPool, scriptService,
indicesQueriesRegistry, clusterService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry,
clusterService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry,
indicesFieldDataCache, globalCheckpointSyncer, searchOperationListeners, indexOperationListeners);
}

View File

@ -68,7 +68,6 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.ThreadPool;
@ -120,7 +119,6 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
private final BigArrays bigArrays;
private final AsyncGlobalCheckpointTask globalCheckpointTask;
private final ScriptService scriptService;
private final IndicesQueriesRegistry queryRegistry;
private final ClusterService clusterService;
private final Client client;
@ -134,7 +132,6 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
BigArrays bigArrays,
ThreadPool threadPool,
ScriptService scriptService,
IndicesQueriesRegistry queryRegistry,
ClusterService clusterService,
Client client,
QueryCache queryCache,
@ -162,7 +159,6 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
this.bigArrays = bigArrays;
this.threadPool = threadPool;
this.scriptService = scriptService;
this.queryRegistry = queryRegistry;
this.clusterService = clusterService;
this.client = client;
this.eventListener = eventListener;
@ -478,7 +474,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
public QueryShardContext newQueryShardContext(int shardId, IndexReader indexReader, LongSupplier nowInMillis) {
return new QueryShardContext(
shardId, indexSettings, indexCache.bitsetFilterCache(), indexFieldData, mapperService(),
similarityService(), scriptService, xContentRegistry, queryRegistry,
similarityService(), scriptService, xContentRegistry,
client, indexReader,
nowInMillis);
}

View File

@ -58,7 +58,7 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuil
builder.endObject();
}
private static ObjectParser<MatchAllQueryBuilder, QueryParseContext> PARSER = new ObjectParser<>(NAME, MatchAllQueryBuilder::new);
private static final ObjectParser<MatchAllQueryBuilder, QueryParseContext> PARSER = new ObjectParser<>(NAME, MatchAllQueryBuilder::new);
static {
declareStandardFields(PARSER);

View File

@ -23,8 +23,9 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.Script;
import java.io.IOException;
@ -36,17 +37,14 @@ public class QueryParseContext implements ParseFieldMatcherSupplier {
private static final ParseField CACHE_KEY = new ParseField("_cache_key").withAllDeprecated("Filters are always used as cache keys");
private final XContentParser parser;
private final IndicesQueriesRegistry indicesQueriesRegistry;
private final ParseFieldMatcher parseFieldMatcher;
private final String defaultScriptLanguage;
public QueryParseContext(IndicesQueriesRegistry registry, XContentParser parser, ParseFieldMatcher parseFieldMatcher) {
this(Script.DEFAULT_SCRIPT_LANG, registry, parser, parseFieldMatcher);
public QueryParseContext(XContentParser parser, ParseFieldMatcher parseFieldMatcher) {
this(Script.DEFAULT_SCRIPT_LANG, parser, parseFieldMatcher);
}
public QueryParseContext(String defaultScriptLanguage, IndicesQueriesRegistry registry, XContentParser parser,
ParseFieldMatcher parseFieldMatcher) {
this.indicesQueriesRegistry = Objects.requireNonNull(registry, "indices queries registry cannot be null");
public QueryParseContext(String defaultScriptLanguage, XContentParser parser, ParseFieldMatcher parseFieldMatcher) {
this.parser = Objects.requireNonNull(parser, "parser cannot be null");
this.parseFieldMatcher = Objects.requireNonNull(parseFieldMatcher, "parse field matcher cannot be null");
this.defaultScriptLanguage = defaultScriptLanguage;
@ -105,7 +103,15 @@ public class QueryParseContext implements ParseFieldMatcherSupplier {
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] query malformed, no start_object after query name");
}
QueryBuilder result = indicesQueriesRegistry.lookup(queryName, parseFieldMatcher, parser.getTokenLocation()).fromXContent(this);
QueryBuilder result;
try {
result = parser.namedObject(QueryBuilder.class, queryName, this);
} catch (UnknownNamedObjectException e) {
// Preserve the error message from 5.0 until we have a compellingly better message so we don't break BWC.
// This intentionally doesn't include the causing exception because that'd change the "root_cause" of any unknown query errors
throw new ParsingException(new XContentLocation(e.getLineNumber(), e.getColumnNumber()),
"no [query] registered for [" + e.getName() + "]");
}
//end_object of the specific query (e.g. match, multi_match etc.) element
if (parser.currentToken() != XContentParser.Token.END_OBJECT) {
throw new ParsingException(parser.getTokenLocation(),

View File

@ -27,7 +27,6 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
@ -43,19 +42,17 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
protected final ScriptService scriptService;
protected final IndexSettings indexSettings;
private final NamedXContentRegistry xContentRegistry;
protected final IndicesQueriesRegistry indicesQueriesRegistry;
protected final Client client;
protected final IndexReader reader;
protected final LongSupplier nowInMillis;
public QueryRewriteContext(IndexSettings indexSettings, MapperService mapperService, ScriptService scriptService,
NamedXContentRegistry xContentRegistry, IndicesQueriesRegistry indicesQueriesRegistry, Client client, IndexReader reader,
NamedXContentRegistry xContentRegistry, Client client, IndexReader reader,
LongSupplier nowInMillis) {
this.mapperService = mapperService;
this.scriptService = scriptService;
this.indexSettings = indexSettings;
this.xContentRegistry = xContentRegistry;
this.indicesQueriesRegistry = indicesQueriesRegistry;
this.client = client;
this.reader = reader;
this.nowInMillis = nowInMillis;
@ -107,7 +104,7 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
* are configured in the index settings. The default script language will always default to Painless.
*/
public QueryParseContext newParseContext(XContentParser parser) {
return new QueryParseContext(indicesQueriesRegistry, parser, indexSettings.getParseFieldMatcher());
return new QueryParseContext(parser, indexSettings.getParseFieldMatcher());
}
public long nowInMillis() {

View File

@ -48,7 +48,6 @@ import org.elasticsearch.index.mapper.ObjectMapper;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.query.support.NestedScope;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
@ -92,7 +91,6 @@ public class QueryShardContext extends QueryRewriteContext {
private final Map<String, Query> namedQueries = new HashMap<>();
private final MapperQueryParser queryParser = new MapperQueryParser(this);
private final IndicesQueriesRegistry indicesQueriesRegistry;
private boolean allowUnmappedFields;
private boolean mapUnmappedFieldAsString;
private NestedScope nestedScope;
@ -100,9 +98,9 @@ public class QueryShardContext extends QueryRewriteContext {
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
IndexFieldDataService indexFieldDataService, MapperService mapperService, SimilarityService similarityService,
ScriptService scriptService, NamedXContentRegistry xContentRegistry, IndicesQueriesRegistry indicesQueriesRegistry,
ScriptService scriptService, NamedXContentRegistry xContentRegistry,
Client client, IndexReader reader, LongSupplier nowInMillis) {
super(indexSettings, mapperService, scriptService, xContentRegistry, indicesQueriesRegistry, client, reader, nowInMillis);
super(indexSettings, mapperService, scriptService, xContentRegistry, client, reader, nowInMillis);
this.shardId = shardId;
this.indexSettings = indexSettings;
this.similarityService = similarityService;
@ -110,14 +108,13 @@ public class QueryShardContext extends QueryRewriteContext {
this.bitsetFilterCache = bitsetFilterCache;
this.indexFieldDataService = indexFieldDataService;
this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields();
this.indicesQueriesRegistry = indicesQueriesRegistry;
this.nestedScope = new NestedScope();
}
public QueryShardContext(QueryShardContext source) {
this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService,
source.similarityService, source.scriptService, source.getXContentRegistry(), source.indicesQueriesRegistry, source.client,
source.similarityService, source.scriptService, source.getXContentRegistry(), source.client,
source.reader, source.nowInMillis);
this.types = source.getTypes();
}

View File

@ -19,8 +19,6 @@
package org.elasticsearch.indices;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.index.DirectoryReader;
@ -41,7 +39,6 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.cluster.routing.RecoverySource;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
@ -106,7 +103,6 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.indices.recovery.PeerRecoveryTargetService;
import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.plugins.PluginsService;
@ -156,7 +152,6 @@ public class IndicesService extends AbstractLifecycleComponent
private final NamedXContentRegistry xContentRegistry;
private final TimeValue shardsClosedTimeout;
private final AnalysisRegistry analysisRegistry;
private final IndicesQueriesRegistry indicesQueriesRegistry;
private final IndexNameExpressionResolver indexNameExpressionResolver;
private final IndexScopedSettings indexScopeSetting;
private final IndicesFieldDataCache indicesFieldDataCache;
@ -187,7 +182,7 @@ public class IndicesService extends AbstractLifecycleComponent
public IndicesService(Settings settings, PluginsService pluginsService, NodeEnvironment nodeEnv, NamedXContentRegistry xContentRegistry,
ClusterSettings clusterSettings, AnalysisRegistry analysisRegistry,
IndicesQueriesRegistry indicesQueriesRegistry, IndexNameExpressionResolver indexNameExpressionResolver,
IndexNameExpressionResolver indexNameExpressionResolver,
MapperRegistry mapperRegistry, NamedWriteableRegistry namedWriteableRegistry,
ThreadPool threadPool, IndexScopedSettings indexScopedSettings, CircuitBreakerService circuitBreakerService,
BigArrays bigArrays, ScriptService scriptService, ClusterService clusterService, Client client,
@ -199,7 +194,6 @@ public class IndicesService extends AbstractLifecycleComponent
this.xContentRegistry = xContentRegistry;
this.shardsClosedTimeout = settings.getAsTime(INDICES_SHARDS_CLOSED_TIMEOUT, new TimeValue(1, TimeUnit.DAYS));
this.analysisRegistry = analysisRegistry;
this.indicesQueriesRegistry = indicesQueriesRegistry;
this.indexNameExpressionResolver = indexNameExpressionResolver;
this.indicesRequestCache = new IndicesRequestCache(settings);
this.indicesQueryCache = new IndicesQueryCache(settings);
@ -451,7 +445,6 @@ public class IndicesService extends AbstractLifecycleComponent
bigArrays,
threadPool,
scriptService,
indicesQueriesRegistry,
clusterService,
client,
indicesQueryCache,
@ -1017,13 +1010,6 @@ public class IndicesService extends AbstractLifecycleComponent
return numUncompletedDeletes.get() > 0;
}
/**
* Returns this nodes {@link IndicesQueriesRegistry}
*/
public IndicesQueriesRegistry getIndicesQueryRegistry() {
return indicesQueriesRegistry;
}
public AnalysisRegistry getAnalysis() {
return analysisRegistry;
}
@ -1268,7 +1254,7 @@ public class IndicesService extends AbstractLifecycleComponent
* of dependencies we pass in a function that can perform the parsing. */
ShardSearchRequest.FilterParser filterParser = bytes -> {
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes)) {
return new QueryParseContext(indicesQueriesRegistry, parser, new ParseFieldMatcher(settings)).parseInnerQueryBuilder();
return new QueryParseContext(parser, new ParseFieldMatcher(settings)).parseInnerQueryBuilder();
}
};
String[] aliases = indexNameExpressionResolver.filteringAliases(state, index, expressions);

View File

@ -1,32 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.indices.query;
import org.elasticsearch.common.xcontent.ParseFieldRegistry;
import org.elasticsearch.index.query.QueryParser;
/**
* Extensions to ParseFieldRegistry to make Guice happy.
*/
public class IndicesQueriesRegistry extends ParseFieldRegistry<QueryParser<?>> {
public IndicesQueriesRegistry() {
super("query");
}
}

View File

@ -94,7 +94,6 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.indices.recovery.PeerRecoverySourceService;
import org.elasticsearch.indices.recovery.PeerRecoveryTargetService;
import org.elasticsearch.indices.recovery.RecoverySettings;
@ -372,7 +371,7 @@ public class Node implements Closeable {
).flatMap(Function.identity()).collect(toList()));
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment);
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry,
settingsModule.getClusterSettings(), analysisModule.getAnalysisRegistry(), searchModule.getQueryParserRegistry(),
settingsModule.getClusterSettings(), analysisModule.getAnalysisRegistry(),
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
threadPool, settingsModule.getIndexScopedSettings(), circuitBreakerService, bigArrays, scriptModule.getScriptService(),
clusterService, client, metaStateService);
@ -410,7 +409,6 @@ public class Node implements Closeable {
final DiscoveryModule discoveryModule = new DiscoveryModule(this.settings, threadPool, transportService,
networkService, clusterService, pluginsService.filterPlugins(DiscoveryPlugin.class));
modules.add(b -> {
b.bind(IndicesQueriesRegistry.class).toInstance(searchModule.getQueryParserRegistry());
b.bind(SearchRequestParsers.class).toInstance(searchModule.getSearchRequestParsers());
b.bind(SearchExtRegistry.class).toInstance(searchModule.getSearchExtRegistry());
b.bind(NamedXContentRegistry.class).toInstance(xContentRegistry);

View File

@ -36,7 +36,6 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestRequest;
@ -195,9 +194,8 @@ public class RestActions {
return queryBuilder;
}
public static QueryBuilder getQueryContent(XContentParser requestParser, IndicesQueriesRegistry indicesQueriesRegistry,
ParseFieldMatcher parseFieldMatcher) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, requestParser, parseFieldMatcher);
public static QueryBuilder getQueryContent(XContentParser requestParser, ParseFieldMatcher parseFieldMatcher) {
QueryParseContext context = new QueryParseContext(requestParser, parseFieldMatcher);
return context.parseTopLevelQueryBuilder();
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.admin.indices;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.action.admin.indices.validate.query.QueryExplanation;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
@ -30,9 +29,6 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
@ -50,11 +46,8 @@ import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader;
public class RestValidateQueryAction extends BaseRestHandler {
private final IndicesQueriesRegistry indicesQueriesRegistry;
@Inject
public RestValidateQueryAction(Settings settings, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry) {
public RestValidateQueryAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_validate/query", this);
controller.registerHandler(POST, "/_validate/query", this);
@ -62,7 +55,6 @@ public class RestValidateQueryAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/_validate/query", this);
controller.registerHandler(GET, "/{index}/{type}/_validate/query", this);
controller.registerHandler(POST, "/{index}/{type}/_validate/query", this);
this.indicesQueriesRegistry = indicesQueriesRegistry;
}
@Override
@ -77,7 +69,7 @@ public class RestValidateQueryAction extends BaseRestHandler {
try {
request.withContentOrSourceParamParserOrNull(parser -> {
if (parser != null) {
validateQueryRequest.query(RestActions.getQueryContent(parser, indicesQueriesRegistry, parseFieldMatcher));
validateQueryRequest.query(RestActions.getQueryContent(parser, parseFieldMatcher));
} else if (request.hasParam("q")) {
validateQueryRequest.query(RestActions.urlParamsToQueryBuilder(request));
}

View File

@ -28,7 +28,6 @@ import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
@ -41,15 +40,11 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.GET;
public class RestCountAction extends AbstractCatAction {
private final IndicesQueriesRegistry indicesQueriesRegistry;
@Inject
public RestCountAction(Settings settings, RestController restController, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry) {
public RestCountAction(Settings settings, RestController restController, RestController controller) {
super(settings);
restController.registerHandler(GET, "/_cat/count", this);
restController.registerHandler(GET, "/_cat/count/{index}", this);
this.indicesQueriesRegistry = indicesQueriesRegistry;
}
@Override
@ -72,7 +67,7 @@ public class RestCountAction extends AbstractCatAction {
searchSourceBuilder.query(queryBuilder);
}
} else {
searchSourceBuilder.query(RestActions.getQueryContent(parser, indicesQueriesRegistry, parseFieldMatcher));
searchSourceBuilder.query(RestActions.getQueryContent(parser, parseFieldMatcher));
}
});
} catch (IOException e) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.document;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.IndicesOptions;
@ -28,9 +27,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
@ -48,11 +45,8 @@ import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHead
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;
public class RestCountAction extends BaseRestHandler {
private final IndicesQueriesRegistry indicesQueriesRegistry;
@Inject
public RestCountAction(Settings settings, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry) {
public RestCountAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_count", this);
controller.registerHandler(GET, "/_count", this);
@ -60,7 +54,6 @@ public class RestCountAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_count", this);
controller.registerHandler(POST, "/{index}/{type}/_count", this);
controller.registerHandler(GET, "/{index}/{type}/_count", this);
this.indicesQueriesRegistry = indicesQueriesRegistry;
}
@Override
@ -76,7 +69,7 @@ public class RestCountAction extends BaseRestHandler {
searchSourceBuilder.query(queryBuilder);
}
} else {
searchSourceBuilder.query(RestActions.getQueryContent(parser, indicesQueriesRegistry, parseFieldMatcher));
searchSourceBuilder.query(RestActions.getQueryContent(parser, parseFieldMatcher));
}
});
countRequest.routing(request.param("routing"));

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
@ -50,13 +49,9 @@ import static org.elasticsearch.rest.RestStatus.OK;
* Rest action for computing a score explanation for specific documents.
*/
public class RestExplainAction extends BaseRestHandler {
private final IndicesQueriesRegistry indicesQueriesRegistry;
@Inject
public RestExplainAction(Settings settings, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry) {
public RestExplainAction(Settings settings, RestController controller) {
super(settings);
this.indicesQueriesRegistry = indicesQueriesRegistry;
controller.registerHandler(GET, "/{index}/{type}/{id}/_explain", this);
controller.registerHandler(POST, "/{index}/{type}/{id}/_explain", this);
}
@ -70,7 +65,7 @@ public class RestExplainAction extends BaseRestHandler {
String queryString = request.param("q");
request.withContentOrSourceParamParserOrNull(parser -> {
if (parser != null) {
explainRequest.query(RestActions.getQueryContent(parser, indicesQueriesRegistry, parseFieldMatcher));
explainRequest.query(RestActions.getQueryContent(parser, parseFieldMatcher));
} else if (queryString != null) {
QueryBuilder query = RestActions.urlParamsToQueryBuilder(request);
explainRequest.query(query);

View File

@ -89,8 +89,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
try {
final QueryParseContext queryParseContext = new QueryParseContext(searchRequestParsers.queryParsers, parser,
parseFieldMatcher);
final QueryParseContext queryParseContext = new QueryParseContext(parser, parseFieldMatcher);
searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext,
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers));
multiRequest.add(searchRequest);

View File

@ -92,7 +92,7 @@ public class RestSearchAction extends BaseRestHandler {
}
searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
if (requestContentParser != null) {
QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, requestContentParser, parseFieldMatcher);
QueryParseContext context = new QueryParseContext(requestContentParser, parseFieldMatcher);
searchRequest.source().parseXContent(context, searchRequestParsers.aggParsers, searchRequestParsers.suggesters,
searchRequestParsers.searchExtParsers);
}

View File

@ -85,7 +85,6 @@ import org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
import org.elasticsearch.index.query.functionscore.WeightBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.plugins.SearchPlugin.AggregationSpec;
import org.elasticsearch.plugins.SearchPlugin.FetchPhaseConstructionContext;
@ -269,7 +268,6 @@ public class SearchModule {
private final boolean transportClient;
private final Map<String, Highlighter> highlighters;
private final Map<String, Suggester<?>> suggesters;
private final IndicesQueriesRegistry queryParserRegistry = new IndicesQueriesRegistry();
private final ParseFieldRegistry<Aggregator.Parser> aggregationParserRegistry = new ParseFieldRegistry<>("aggregation");
private final ParseFieldRegistry<PipelineAggregator.Parser> pipelineAggregationParserRegistry = new ParseFieldRegistry<>(
"pipline_aggregation");
@ -304,7 +302,7 @@ public class SearchModule {
registerFetchSubPhases(plugins);
registerSearchExts(plugins);
registerShapes();
searchRequestParsers = new SearchRequestParsers(queryParserRegistry, aggregatorParsers, getSuggesters(), searchExtParserRegistry);
searchRequestParsers = new SearchRequestParsers(aggregatorParsers, getSuggesters(), searchExtParserRegistry);
}
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
@ -319,10 +317,6 @@ public class SearchModule {
return new Suggesters(suggesters);
}
public IndicesQueriesRegistry getQueryParserRegistry() {
return queryParserRegistry;
}
public SearchRequestParsers getSearchRequestParsers() {
return searchRequestParsers;
}
@ -442,11 +436,12 @@ public class SearchModule {
if (false == transportClient) {
aggregationParserRegistry.register(spec.getParser(), spec.getName());
}
namedWriteables.add(new Entry(AggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
namedWriteables.add(
new NamedWriteableRegistry.Entry(AggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
for (Map.Entry<String, Writeable.Reader<? extends InternalAggregation>> t : spec.getResultReaders().entrySet()) {
String writeableName = t.getKey();
Writeable.Reader<? extends InternalAggregation> internalReader = t.getValue();
namedWriteables.add(new Entry(InternalAggregation.class, writeableName, internalReader));
namedWriteables.add(new NamedWriteableRegistry.Entry(InternalAggregation.class, writeableName, internalReader));
}
}
@ -535,10 +530,13 @@ public class SearchModule {
if (false == transportClient) {
pipelineAggregationParserRegistry.register(spec.getParser(), spec.getName());
}
namedWriteables.add(new Entry(PipelineAggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
namedWriteables.add(new Entry(PipelineAggregator.class, spec.getName().getPreferredName(), spec.getAggregatorReader()));
namedWriteables.add(
new NamedWriteableRegistry.Entry(PipelineAggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
namedWriteables.add(
new NamedWriteableRegistry.Entry(PipelineAggregator.class, spec.getName().getPreferredName(), spec.getAggregatorReader()));
for (Map.Entry<String, Writeable.Reader<? extends InternalAggregation>> resultReader : spec.getResultReaders().entrySet()) {
namedWriteables.add(new Entry(InternalAggregation.class, resultReader.getKey(), resultReader.getValue()));
namedWriteables
.add(new NamedWriteableRegistry.Entry(InternalAggregation.class, resultReader.getKey(), resultReader.getValue()));
}
}
@ -549,14 +547,14 @@ public class SearchModule {
}
private void registerRescorers() {
namedWriteables.add(new Entry(RescoreBuilder.class, QueryRescorerBuilder.NAME, QueryRescorerBuilder::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(RescoreBuilder.class, QueryRescorerBuilder.NAME, QueryRescorerBuilder::new));
}
private void registerSorts() {
namedWriteables.add(new Entry(SortBuilder.class, GeoDistanceSortBuilder.NAME, GeoDistanceSortBuilder::new));
namedWriteables.add(new Entry(SortBuilder.class, ScoreSortBuilder.NAME, ScoreSortBuilder::new));
namedWriteables.add(new Entry(SortBuilder.class, ScriptSortBuilder.NAME, ScriptSortBuilder::new));
namedWriteables.add(new Entry(SortBuilder.class, FieldSortBuilder.NAME, FieldSortBuilder::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, GeoDistanceSortBuilder.NAME, GeoDistanceSortBuilder::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, ScoreSortBuilder.NAME, ScoreSortBuilder::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, ScriptSortBuilder.NAME, ScriptSortBuilder::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, FieldSortBuilder.NAME, FieldSortBuilder::new));
}
private <T> void registerFromPlugin(List<SearchPlugin> plugins, Function<SearchPlugin, List<T>> producer, Consumer<T> consumer) {
@ -568,9 +566,9 @@ public class SearchModule {
}
public static void registerSmoothingModels(List<Entry> namedWriteables) {
namedWriteables.add(new Entry(SmoothingModel.class, Laplace.NAME, Laplace::new));
namedWriteables.add(new Entry(SmoothingModel.class, LinearInterpolation.NAME, LinearInterpolation::new));
namedWriteables.add(new Entry(SmoothingModel.class, StupidBackoff.NAME, StupidBackoff::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SmoothingModel.class, Laplace.NAME, Laplace::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SmoothingModel.class, LinearInterpolation.NAME, LinearInterpolation::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(SmoothingModel.class, StupidBackoff.NAME, StupidBackoff::new));
}
private Map<String, Suggester<?>> setupSuggesters(List<SearchPlugin> plugins) {
@ -581,7 +579,7 @@ public class SearchModule {
@Override
public void register(String name, Suggester<?> t) {
super.register(name, t);
namedWriteables.add(new Entry(SuggestionBuilder.class, name, t));
namedWriteables.add(new NamedWriteableRegistry.Entry(SuggestionBuilder.class, name, t));
}
};
suggesters.register("phrase", PhraseSuggester.INSTANCE);
@ -619,7 +617,7 @@ public class SearchModule {
//weight doesn't have its own parser, so every function supports it out of the box.
//Can be a single function too when not associated to any other function, which is why it needs to be registered manually here.
namedWriteables.add(new Entry(ScoreFunctionBuilder.class, WeightBuilder.NAME, WeightBuilder::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(ScoreFunctionBuilder.class, WeightBuilder.NAME, WeightBuilder::new));
registerFromPlugin(plugins, SearchPlugin::getScoreFunctions, this::registerScoreFunction);
}
@ -646,7 +644,7 @@ public class SearchModule {
* Register a new ValueFormat.
*/
private void registerValueFormat(String name, Writeable.Reader<? extends DocValueFormat> reader) {
namedWriteables.add(new Entry(DocValueFormat.class, name, reader));
namedWriteables.add(new NamedWriteableRegistry.Entry(DocValueFormat.class, name, reader));
}
private void registerSignificanceHeuristics(List<SearchPlugin> plugins) {
@ -662,7 +660,8 @@ public class SearchModule {
private void registerSignificanceHeuristic(SearchExtensionSpec<SignificanceHeuristic, SignificanceHeuristicParser> heuristic) {
significanceHeuristicParserRegistry.register(heuristic.getParser(), heuristic.getName());
namedWriteables.add(new Entry(SignificanceHeuristic.class, heuristic.getName().getPreferredName(), heuristic.getReader()));
namedWriteables.add(new NamedWriteableRegistry.Entry(SignificanceHeuristic.class, heuristic.getName().getPreferredName(),
heuristic.getReader()));
}
private void registerMovingAverageModels(List<SearchPlugin> plugins) {
@ -677,7 +676,8 @@ public class SearchModule {
private void registerMovingAverageModel(SearchExtensionSpec<MovAvgModel, MovAvgModel.AbstractModelParser> movAvgModel) {
movingAverageModelParserRegistry.register(movAvgModel.getParser(), movAvgModel.getName());
namedWriteables.add(new Entry(MovAvgModel.class, movAvgModel.getName().getPreferredName(), movAvgModel.getReader()));
namedWriteables.add(
new NamedWriteableRegistry.Entry(MovAvgModel.class, movAvgModel.getName().getPreferredName(), movAvgModel.getReader()));
}
private void registerFetchSubPhases(List<SearchPlugin> plugins) {
@ -700,7 +700,7 @@ public class SearchModule {
private void registerSearchExt(SearchExtSpec<?> spec) {
searchExtParserRegistry.register(spec.getParser(), spec.getName());
namedWriteables.add(new Entry(SearchExtBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
namedWriteables.add(new NamedWriteableRegistry.Entry(SearchExtBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
}
private void registerFetchSubPhase(FetchSubPhase subPhase) {
@ -774,8 +774,9 @@ public class SearchModule {
}
private void registerQuery(QuerySpec<?> spec) {
queryParserRegistry.register(spec.getParser(), spec.getName());
namedWriteables.add(new Entry(QueryBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
namedWriteables.add(new NamedWriteableRegistry.Entry(QueryBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
namedXContents.add(new NamedXContentRegistry.Entry(QueryBuilder.class, spec.getName(),
(p, c) -> spec.getParser().fromXContent((QueryParseContext) c)));
}
public FetchPhase getFetchPhase() {

View File

@ -20,7 +20,6 @@
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;
@ -33,15 +32,6 @@ public class SearchRequestParsers {
// methods split across RestSearchAction and SearchSourceBuilder should be moved here
// TODO: make all members private once parsing functions are 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, SearchExtRegistry)
*/
public final IndicesQueriesRegistry queryParsers;
// TODO: AggregatorParsers should be removed and the underlying maps of agg
// and pipeline agg parsers should be here
/**
@ -64,9 +54,7 @@ public class SearchRequestParsers {
*/
public final SearchExtRegistry searchExtParsers;
public SearchRequestParsers(IndicesQueriesRegistry queryParsers, AggregatorParsers aggParsers, Suggesters suggesters,
SearchExtRegistry searchExtParsers) {
this.queryParsers = queryParsers;
public SearchRequestParsers(AggregatorParsers aggParsers, Suggesters suggesters, SearchExtRegistry searchExtParsers) {
this.aggParsers = aggParsers;
this.suggesters = suggesters;
this.searchExtParsers = searchExtParsers;

View File

@ -20,15 +20,18 @@
package org.elasticsearch.action.search;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
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;
@ -38,6 +41,7 @@ import org.elasticsearch.test.rest.FakeRestRequest;
import java.io.IOException;
import static java.util.Collections.singletonList;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
@ -168,13 +172,12 @@ public class MultiSearchRequestTests extends ESTestCase {
private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(data)).build();
return RestMultiSearchAction.parseRequest(restRequest, true, parsers(), ParseFieldMatcher.EMPTY);
return RestMultiSearchAction.parseRequest(restRequest, true, new SearchRequestParsers(null, null, null), ParseFieldMatcher.EMPTY);
}
private SearchRequestParsers parsers() {
IndicesQueriesRegistry registry = new IndicesQueriesRegistry();
QueryParser<MatchAllQueryBuilder> parser = MatchAllQueryBuilder::fromXContent;
registry.register(parser, MatchAllQueryBuilder.NAME);
return new SearchRequestParsers(registry, null, null, null);
@Override
protected NamedXContentRegistry xContentRegistry() {
return new NamedXContentRegistry(singletonList(new NamedXContentRegistry.Entry(QueryBuilder.class,
new ParseField(MatchAllQueryBuilder.NAME), (p, c) -> MatchAllQueryBuilder.fromXContent((QueryParseContext) c))));
}
}

View File

@ -64,7 +64,6 @@ import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptService;
@ -110,7 +109,6 @@ public class IndexModuleTests extends ESTestCase {
private CircuitBreakerService circuitBreakerService;
private BigArrays bigArrays;
private ScriptService scriptService;
private IndicesQueriesRegistry indicesQueriesRegistry;
private ClusterService clusterService;
@Override
@ -130,7 +128,6 @@ public class IndexModuleTests extends ESTestCase {
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
scriptService = new ScriptService(settings, environment, new ResourceWatcherService(settings, threadPool), scriptEngineRegistry,
scriptContextRegistry, scriptSettings);
indicesQueriesRegistry = new IndicesQueriesRegistry();
clusterService = ClusterServiceUtils.createClusterService(threadPool);
nodeEnvironment = new NodeEnvironment(settings, environment);
mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
@ -145,7 +142,7 @@ public class IndexModuleTests extends ESTestCase {
private IndexService newIndexService(IndexModule module) throws IOException {
return module.newIndexService(nodeEnvironment, xContentRegistry(), deleter, circuitBreakerService, bigArrays, threadPool,
scriptService, indicesQueriesRegistry, clusterService, null, indicesQueryCache, mapperRegistry, shardId -> {},
scriptService, clusterService, null, indicesQueryCache, mapperRegistry, shardId -> {},
new IndicesFieldDataCache(settings, listener));
}

View File

@ -71,7 +71,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
}
public void testIsFieldWithinQueryEmptyReader() throws IOException {
QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null, null,
QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null,
() -> nowInMillis);
IndexReader reader = new MultiReader();
DateFieldType ft = new DateFieldType();
@ -82,7 +82,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
private void doTestIsFieldWithinQuery(DateFieldType ft, DirectoryReader reader,
DateTimeZone zone, DateMathParser alternateFormat) throws IOException {
QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null, null,
QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null,
() -> nowInMillis);
assertEquals(Relation.INTERSECTS, ft.isFieldWithinQuery(reader, "2015-10-09", "2016-01-02",
randomBoolean(), randomBoolean(), null, null, context));
@ -130,7 +130,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
DateFieldType ft2 = new DateFieldType();
ft2.setName("my_date2");
QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null, null,
QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null,
() -> nowInMillis);
assertEquals(Relation.DISJOINT, ft2.isFieldWithinQuery(reader, "2015-10-09", "2016-01-02", false, false, null, null, context));
IOUtils.close(reader, w, dir);
@ -166,7 +166,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
QueryShardContext context = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(),
indexSettings),
null, null, null, null, null, xContentRegistry(), null, null, null, () -> nowInMillis);
null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
MappedFieldType ft = createDefaultFieldType();
ft.setName("field");
String date = "2015-10-12T14:10:55";
@ -185,7 +185,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
QueryShardContext context = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings),
null, null, null, null, null, xContentRegistry(), null, null, null, () -> nowInMillis);
null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
MappedFieldType ft = createDefaultFieldType();
ft.setName("field");
String date1 = "2015-10-12T14:10:55";

View File

@ -74,7 +74,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase {
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAsciiOfLengthBetween(1, 10), indexSettings);
QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), null,
QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
null, null, () -> nowInMillis);
RangeFieldMapper.RangeFieldType ft = new RangeFieldMapper.RangeFieldType(type);
ft.setName(FIELDNAME);

View File

@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.hamcrest.Matchers;

View File

@ -22,13 +22,13 @@ import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.SearchModule;
@ -62,19 +62,24 @@ public class InnerHitBuilderTests extends ESTestCase {
private static final int NUMBER_OF_TESTBUILDERS = 20;
private static NamedWriteableRegistry namedWriteableRegistry;
private static IndicesQueriesRegistry indicesQueriesRegistry;
private static NamedXContentRegistry xContentRegistry;
@BeforeClass
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
@AfterClass
public static void afterClass() throws Exception {
namedWriteableRegistry = null;
indicesQueriesRegistry = null;
xContentRegistry = null;
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
public void testSerialization() throws Exception {
@ -98,7 +103,7 @@ public class InnerHitBuilderTests extends ESTestCase {
}
XContentParser parser = createParser(shuffled);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
InnerHitBuilder secondInnerHits = InnerHitBuilder.fromXContent(context);
assertThat(innerHit, not(sameInstance(secondInnerHits)));
assertThat(innerHit, equalTo(secondInnerHits));

View File

@ -24,9 +24,9 @@ import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;
import org.junit.After;
@ -38,12 +38,11 @@ import java.io.IOException;
import static java.util.Collections.emptyList;
public class QueryParseContextTests extends ESTestCase {
private static IndicesQueriesRegistry indicesQueriesRegistry;
private static NamedXContentRegistry xContentRegistry;
@BeforeClass
public static void init() {
indicesQueriesRegistry = new SearchModule(Settings.EMPTY, false, emptyList()).getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, emptyList()).getNamedXContents());
}
private ThreadContext threadContext;
@ -64,7 +63,7 @@ public class QueryParseContextTests extends ESTestCase {
QueryBuilder query = new MatchQueryBuilder("foo", "bar");
String requestBody = "{ \"query\" : " + query.toString() + "}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
QueryBuilder actual = context.parseTopLevelQueryBuilder();
assertEquals(query, actual);
}
@ -73,7 +72,7 @@ public class QueryParseContextTests extends ESTestCase {
public void testParseTopLevelBuilderEmptyObject() throws IOException {
String requestBody = "{}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
QueryBuilder query = context.parseTopLevelQueryBuilder();
assertNull(query);
}
@ -82,7 +81,7 @@ public class QueryParseContextTests extends ESTestCase {
public void testParseTopLevelBuilderUnknownParameter() throws IOException {
String requestBody = "{ \"foo\" : \"bar\"}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseTopLevelQueryBuilder());
assertEquals("request does not support [foo]", exception.getMessage());
}
@ -92,7 +91,7 @@ public class QueryParseContextTests extends ESTestCase {
QueryBuilder query = new MatchQueryBuilder("foo", "bar");
String source = query.toString();
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
QueryBuilder actual = context.parseInnerQueryBuilder();
assertEquals(query, actual);
}
@ -103,30 +102,35 @@ public class QueryParseContextTests extends ESTestCase {
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
parser.nextToken();
parser.nextToken(); // don't start with START_OBJECT to provoke exception
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
assertEquals("[_na] query malformed, must start with start_object", exception.getMessage());
}
source = "{}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> context.parseInnerQueryBuilder());
assertEquals("query malformed, empty clause found at [1:2]", exception.getMessage());
}
source = "{ \"foo\" : \"bar\" }";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
assertEquals("[foo] query malformed, no start_object after query name", exception.getMessage());
}
source = "{ \"foo\" : {} }";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
assertEquals("no [query] registered for [foo]", exception.getMessage());
}
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
}

View File

@ -48,7 +48,7 @@ public class QueryShardContextTests extends ESTestCase {
when(mapperService.getIndexSettings()).thenReturn(indexSettings);
final long nowInMillis = randomPositiveLong();
QueryShardContext context = new QueryShardContext(
0, indexSettings, null, null, mapperService, null, null, xContentRegistry(), null, null, null,
0, indexSettings, null, null, mapperService, null, null, xContentRegistry(), null, null,
() -> nowInMillis);
context.setAllowUnmappedFields(false);

View File

@ -37,7 +37,7 @@ public class RangeQueryRewriteTests extends ESSingleNodeTestCase {
IndexService indexService = createIndex("test");
IndexReader reader = new MultiReader();
QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(),
null, null, xContentRegistry(), null, null, reader, null);
null, null, xContentRegistry(), null, reader, null);
RangeQueryBuilder range = new RangeQueryBuilder("foo");
assertEquals(Relation.DISJOINT, range.getRelation(context));
}
@ -54,7 +54,7 @@ public class RangeQueryRewriteTests extends ESSingleNodeTestCase {
indexService.mapperService().merge("type",
new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false);
QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(),
null, null, xContentRegistry(), null, null, null, null);
null, null, xContentRegistry(), null, null, null);
RangeQueryBuilder range = new RangeQueryBuilder("foo");
// can't make assumptions on a missing reader, so it must return INTERSECT
assertEquals(Relation.INTERSECTS, range.getRelation(context));
@ -73,7 +73,7 @@ public class RangeQueryRewriteTests extends ESSingleNodeTestCase {
new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false);
IndexReader reader = new MultiReader();
QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(),
null, null, xContentRegistry(), null, null, reader, null);
null, null, xContentRegistry(), null, reader, null);
RangeQueryBuilder range = new RangeQueryBuilder("foo");
// no values -> DISJOINT
assertEquals(Relation.DISJOINT, range.getRelation(context));

View File

@ -34,37 +34,15 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MockFieldMapper;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.emptyList;
import static org.hamcrest.Matchers.equalTo;
public class SimpleQueryParserTests extends ESTestCase {
private static IndicesQueriesRegistry indicesQueriesRegistry;
/**
* setup for the whole base test class
*/
@BeforeClass
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
}
@AfterClass
public static void afterClass() throws Exception {
indicesQueriesRegistry = null;
}
private static class MockSimpleQueryParser extends SimpleQueryParser {
public MockSimpleQueryParser(Analyzer analyzer, Map<String, Float> weights, int flags, Settings settings) {
super(analyzer, weights, flags, settings, null);
@ -148,7 +126,7 @@ public class SimpleQueryParserTests extends ESTestCase {
IndexMetaData indexState = IndexMetaData.builder("index").settings(indexSettings).build();
IndexSettings settings = new IndexSettings(indexState, Settings.EMPTY);
QueryShardContext mockShardContext = new QueryShardContext(0, settings, null, null, null, null, null, xContentRegistry(),
indicesQueriesRegistry, null, null, System::currentTimeMillis) {
null, null, System::currentTimeMillis) {
@Override
public MappedFieldType fieldMapper(String name) {
return new MockFieldMapper.FakeFieldType();
@ -161,7 +139,7 @@ public class SimpleQueryParserTests extends ESTestCase {
assertEquals(new TermQuery(new Term("foo.quote", "bar")), parser.parse("\"bar\""));
// Now check what happens if foo.quote does not exist
mockShardContext = new QueryShardContext(0, settings, null, null, null, null, null, xContentRegistry(), indicesQueriesRegistry,
mockShardContext = new QueryShardContext(0, settings, null, null, null, null, null, xContentRegistry(),
null, null, System::currentTimeMillis) {
@Override
public MappedFieldType fieldMapper(String name) {

View File

@ -25,10 +25,10 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.builder.SearchSourceBuilder;
@ -54,7 +54,7 @@ public abstract class AbstractSearchTestCase extends ESTestCase {
protected NamedWriteableRegistry namedWriteableRegistry;
protected SearchRequestParsers searchRequestParsers;
private TestSearchExtPlugin searchExtPlugin;
protected IndicesQueriesRegistry queriesRegistry;
private NamedXContentRegistry xContentRegistry;
public void setUp() throws Exception {
super.setUp();
@ -65,8 +65,13 @@ public abstract class AbstractSearchTestCase extends ESTestCase {
entries.addAll(indicesModule.getNamedWriteables());
entries.addAll(searchModule.getNamedWriteables());
namedWriteableRegistry = new NamedWriteableRegistry(entries);
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
searchRequestParsers = searchModule.getSearchRequestParsers();
queriesRegistry = searchModule.getQueryParserRegistry();
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
protected SearchSourceBuilder createSearchSourceBuilder() {

View File

@ -19,20 +19,16 @@
package org.elasticsearch.search;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.inject.ModuleTestCase;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.functionscore.GaussDecayFunctionBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
@ -70,16 +66,17 @@ import org.elasticsearch.search.suggest.term.TermSuggester;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toSet;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.notNullValue;
public class SearchModuleTests extends ModuleTestCase {
@ -109,8 +106,8 @@ public class SearchModuleTests extends ModuleTestCase {
GaussDecayFunctionBuilder.PARSER));
}
};
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, singletonList(registersDupeScoreFunction));
expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(searchModule.getNamedXContents()));
expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(
new SearchModule(Settings.EMPTY, false, singletonList(registersDupeScoreFunction)).getNamedXContents()));
SearchPlugin registersDupeSignificanceHeuristic = new SearchPlugin() {
@Override
@ -144,8 +141,8 @@ public class SearchModuleTests extends ModuleTestCase {
return singletonList(new QuerySpec<>(TermQueryBuilder.NAME, TermQueryBuilder::new, TermQueryBuilder::fromXContent));
}
};
expectThrows(IllegalArgumentException.class, () -> new SearchModule(Settings.EMPTY, false,
singletonList(registersDupeQuery)));
expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(
new SearchModule(Settings.EMPTY, false, singletonList(registersDupeQuery)).getNamedXContents()));
SearchPlugin registersDupeAggregation = new SearchPlugin() {
public List<AggregationSpec> getAggregations() {
@ -200,31 +197,22 @@ public class SearchModuleTests extends ModuleTestCase {
}
public void testRegisteredQueries() throws IOException {
SearchModule module = new SearchModule(Settings.EMPTY, false, emptyList());
List<String> allSupportedQueries = new ArrayList<>();
Collections.addAll(allSupportedQueries, NON_DEPRECATED_QUERIES);
Collections.addAll(allSupportedQueries, DEPRECATED_QUERIES);
String[] supportedQueries = allSupportedQueries.toArray(new String[allSupportedQueries.size()]);
assertThat(module.getQueryParserRegistry().getNames(), containsInAnyOrder(supportedQueries));
SearchModule module = new SearchModule(Settings.EMPTY, false, emptyList());
IndicesQueriesRegistry indicesQueriesRegistry = module.getQueryParserRegistry();
XContentParser dummyParser = createParser(JsonXContent.jsonXContent, new BytesArray("{}"));
for (String queryName : supportedQueries) {
indicesQueriesRegistry.lookup(queryName, ParseFieldMatcher.EMPTY, dummyParser.getTokenLocation());
}
Set<String> registeredNonDeprecated = module.getNamedXContents().stream()
.filter(e -> e.categoryClass.equals(QueryBuilder.class))
.map(e -> e.name.getPreferredName())
.collect(toSet());
Set<String> registeredAll = module.getNamedXContents().stream()
.filter(e -> e.categoryClass.equals(QueryBuilder.class))
.flatMap(e -> Arrays.stream(e.name.getAllNamesIncludedDeprecated()))
.collect(toSet());
for (String queryName : NON_DEPRECATED_QUERIES) {
QueryParser<?> queryParser = indicesQueriesRegistry.lookup(queryName, ParseFieldMatcher.STRICT, dummyParser.getTokenLocation());
assertThat(queryParser, notNullValue());
}
for (String queryName : DEPRECATED_QUERIES) {
try {
indicesQueriesRegistry.lookup(queryName, ParseFieldMatcher.STRICT, dummyParser.getTokenLocation());
fail("query is deprecated, getQueryParser should have failed in strict mode");
} catch(IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Deprecated field [" + queryName + "] used"));
}
}
assertThat(registeredNonDeprecated, containsInAnyOrder(NON_DEPRECATED_QUERIES));
assertThat(registeredAll, containsInAnyOrder(allSupportedQueries.toArray(new String[0])));
}
public void testRegisterAggregation() {

View File

@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
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.internal.SearchContext;
import org.elasticsearch.test.ESSingleNodeTestCase;
@ -61,9 +60,8 @@ public class AggregationCollectorTests extends ESSingleNodeTestCase {
private boolean needsScores(IndexService index, String agg) throws IOException {
AggregatorParsers parser = getInstanceFromNode(SearchRequestParsers.class).aggParsers;
IndicesQueriesRegistry queriesRegistry = getInstanceFromNode(IndicesQueriesRegistry.class);
XContentParser aggParser = createParser(JsonXContent.jsonXContent, agg);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, aggParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(aggParser, ParseFieldMatcher.STRICT);
aggParser.nextToken();
SearchContext context = createSearchContext(index);
final AggregatorFactories factories = parser.parseAggregators(parseContext).build(context, null);

View File

@ -22,16 +22,16 @@ package org.elasticsearch.search.aggregations;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.ESTestCase;
import java.util.Random;
@ -50,7 +50,7 @@ public class AggregatorParsingTests extends ESTestCase {
}
protected AggregatorParsers aggParsers;
protected IndicesQueriesRegistry queriesRegistry;
private NamedXContentRegistry xContentRegistry;
protected ParseFieldMatcher parseFieldMatcher;
/**
@ -73,7 +73,7 @@ public class AggregatorParsingTests extends ESTestCase {
String type = randomAsciiOfLengthBetween(1, 10);
currentTypes[i] = type;
}
queriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
parseFieldMatcher = ParseFieldMatcher.STRICT;
}
@ -95,7 +95,7 @@ public class AggregatorParsingTests extends ESTestCase {
.endObject();
try {
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();
@ -132,7 +132,7 @@ public class AggregatorParsingTests extends ESTestCase {
.endObject();
try {
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();
@ -171,7 +171,7 @@ public class AggregatorParsingTests extends ESTestCase {
.endObject();
try {
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();
@ -199,7 +199,7 @@ public class AggregatorParsingTests extends ESTestCase {
.endObject();
try {
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();
@ -228,7 +228,7 @@ public class AggregatorParsingTests extends ESTestCase {
.endObject();
try {
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();
@ -257,7 +257,7 @@ public class AggregatorParsingTests extends ESTestCase {
.endObject();
try {
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();
@ -265,4 +265,9 @@ public class AggregatorParsingTests extends ESTestCase {
// All Good
}
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -33,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.ESTestCase;
@ -64,7 +64,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
private NamedWriteableRegistry namedWriteableRegistry;
protected AggregatorParsers aggParsers;
protected IndicesQueriesRegistry queriesRegistry;
private NamedXContentRegistry xContentRegistry;
protected ParseFieldMatcher parseFieldMatcher;
protected abstract AB createTestAggregatorBuilder();
@ -85,7 +85,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
entries.addAll(indicesModule.getNamedWriteables());
entries.addAll(searchModule.getNamedWriteables());
namedWriteableRegistry = new NamedWriteableRegistry(entries);
queriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
aggParsers = searchModule.getSearchRequestParsers().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)];
@ -96,6 +96,11 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
parseFieldMatcher = ParseFieldMatcher.STRICT;
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
/**
* Generic test that creates new AggregatorFactory from the test
* AggregatorFactory and checks both for equality and asserts equality on
@ -111,7 +116,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
factoriesBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentBuilder shuffled = shuffleXContent(builder);
XContentParser parser = createParser(shuffled);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken());
assertEquals(testAgg.name, parser.currentName());

View File

@ -34,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
import org.elasticsearch.test.AbstractQueryTestCase;
@ -65,7 +64,6 @@ public abstract class BasePipelineAggregationTestCase<AF extends AbstractPipelin
private NamedWriteableRegistry namedWriteableRegistry;
protected AggregatorParsers aggParsers;
protected IndicesQueriesRegistry queriesRegistry;
protected ParseFieldMatcher parseFieldMatcher;
protected abstract AF createTestAggregatorFactory();
@ -86,7 +84,6 @@ public abstract class BasePipelineAggregationTestCase<AF extends AbstractPipelin
entries.addAll(indicesModule.getNamedWriteables());
entries.addAll(searchModule.getNamedWriteables());
namedWriteableRegistry = new NamedWriteableRegistry(entries);
queriesRegistry = searchModule.getQueryParserRegistry();
aggParsers = searchModule.getSearchRequestParsers().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)];
@ -113,7 +110,7 @@ public abstract class BasePipelineAggregationTestCase<AF extends AbstractPipelin
factoriesBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentBuilder shuffled = shuffleXContent(builder);
XContentParser parser = createParser(shuffled);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
String contentString = factoriesBuilder.toString();
logger.info("Content string: {}", contentString);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());

View File

@ -23,20 +23,16 @@ import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.Matchers.instanceOf;
public class GeoHashGridParserTests extends ESTestCase {
private static final IndicesQueriesRegistry mockRegistry = new IndicesQueriesRegistry();
public void testParseValidFromInts() throws Exception {
int precision = randomIntBetween(1, 12);
XContentParser stParser = createParser(JsonXContent.jsonXContent,
"{\"field\":\"my_loc\", \"precision\":" + precision + ", \"size\": 500, \"shard_size\": 550}");
QueryParseContext parseContext = new QueryParseContext(mockRegistry,
stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
// can create a factory
@ -47,7 +43,7 @@ public class GeoHashGridParserTests extends ESTestCase {
int precision = randomIntBetween(1, 12);
XContentParser stParser = createParser(JsonXContent.jsonXContent,
"{\"field\":\"my_loc\", \"precision\":\"" + precision + "\", \"size\": \"500\", \"shard_size\": \"550\"}");
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
// can create a factory
@ -56,7 +52,7 @@ public class GeoHashGridParserTests extends ESTestCase {
public void testParseErrorOnNonIntPrecision() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"2.0\"}");
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {
@ -70,7 +66,7 @@ public class GeoHashGridParserTests extends ESTestCase {
public void testParseErrorOnBooleanPrecision() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":false}");
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {
@ -83,7 +79,7 @@ public class GeoHashGridParserTests extends ESTestCase {
public void testParseErrorOnPrecisionOutOfRange() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"13\"}");
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {

View File

@ -100,7 +100,7 @@ public class ExtendedBoundsTests extends ESTestCase {
SearchContext context = mock(SearchContext.class);
QueryShardContext qsc = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null,
null, xContentRegistry(), null, null, null, () -> now);
null, xContentRegistry(), null, null, () -> now);
when(context.getQueryShardContext()).thenReturn(qsc);
FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
DocValueFormat format = new DocValueFormat.DateTime(formatter, DateTimeZone.UTC);

View File

@ -35,7 +35,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchShardTarget;
@ -267,11 +266,10 @@ public class SignificanceHeuristicTests extends ESTestCase {
protected void checkParseException(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry,
SearchContext searchContext, String faultyHeuristicDefinition, String expectedError) throws IOException {
IndicesQueriesRegistry registry = new IndicesQueriesRegistry();
try {
XContentParser stParser = createParser(JsonXContent.jsonXContent,
"{\"field\":\"text\", " + faultyHeuristicDefinition + ",\"min_doc_count\":200}");
QueryParseContext parseContext = new QueryParseContext(registry, stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
stParser.nextToken();
SignificantTermsAggregationBuilder.getParser(significanceHeuristicParserRegistry).parse("testagg", parseContext);
fail();
@ -293,8 +291,7 @@ public class SignificanceHeuristicTests extends ESTestCase {
private SignificanceHeuristic parseSignificanceHeuristic(
ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry, SearchContext searchContext,
XContentParser stParser) throws IOException {
IndicesQueriesRegistry registry = new IndicesQueriesRegistry();
QueryParseContext parseContext = new QueryParseContext(registry, stParser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(stParser, ParseFieldMatcher.STRICT);
stParser.nextToken();
SignificantTermsAggregationBuilder aggregatorFactory =
(SignificantTermsAggregationBuilder) SignificantTermsAggregationBuilder.getParser(

View File

@ -28,7 +28,6 @@ import org.elasticsearch.index.query.MatchNoneQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter;
@ -89,8 +88,7 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
builder.endObject();
XContentParser parser = createParser(shuffleXContent(builder));
parser.nextToken();
QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser,
ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
FiltersAggregationBuilder filters = FiltersAggregationBuilder.parse("agg_name", context);
// The other bucket is disabled by default
assertFalse(filters.otherBucket());
@ -102,7 +100,7 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
builder.endObject();
parser = createParser(shuffleXContent(builder));
parser.nextToken();
context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
filters = FiltersAggregationBuilder.parse("agg_name", context);
// but setting a key enables it automatically
assertTrue(filters.otherBucket());
@ -115,7 +113,7 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
builder.endObject();
parser = createParser(shuffleXContent(builder));
parser.nextToken();
context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
filters = FiltersAggregationBuilder.parse("agg_name", context);
// unless the other bucket is explicitly disabled
assertFalse(filters.otherBucket());

View File

@ -19,10 +19,8 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.AggregationInitializationException;
@ -33,6 +31,7 @@ import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilderTests;
import org.elasticsearch.search.sort.ScriptSortBuilder.ScriptSortType;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.AbstractQueryTestCase;
import java.util.ArrayList;
import java.util.Collections;
@ -188,7 +187,7 @@ public class TopHitsTests extends BaseAggregationTestCase<TopHitsAggregationBuil
"}";
try {
XContentParser parser = createParser(JsonXContent.jsonXContent, source);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
aggParsers.parseAggregators(parseContext);
fail();

View File

@ -47,7 +47,7 @@ public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase<Exte
.string();
XContentParser parser = createParser(JsonXContent.jsonXContent, content);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
parser.nextToken(); // skip object start
ExtendedStatsBucketPipelineAggregationBuilder builder = (ExtendedStatsBucketPipelineAggregationBuilder) aggParsers

View File

@ -52,7 +52,7 @@ public class PercentilesBucketTests extends AbstractBucketMetricsTestCase<Percen
.string();
XContentParser parser = createParser(JsonXContent.jsonXContent, content);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
parser.nextToken(); // skip object start
PercentilesBucketPipelineAggregationBuilder builder = (PercentilesBucketPipelineAggregationBuilder) aggParsers

View File

@ -107,7 +107,7 @@ public class MovAvgTests extends BasePipelineAggregationTestCase<MovAvgPipelineA
" }" +
"}";
XContentParser parser = createParser(JsonXContent.jsonXContent, json);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken());
assertEquals(expected.getName(), parser.currentName());

View File

@ -32,7 +32,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter;
@ -43,9 +42,7 @@ import java.util.Collections;
import java.util.TreeSet;
public class IncludeExcludeTests extends ESTestCase {
private final ParseFieldMatcher parseFieldMatcher = ParseFieldMatcher.STRICT;
private final IndicesQueriesRegistry queriesRegistry = new IndicesQueriesRegistry();
public void testEmptyTermsWithOrds() throws IOException {
IncludeExclude inexcl = new IncludeExclude(
@ -237,7 +234,7 @@ public class IncludeExcludeTests extends ESTestCase {
assertEquals(field.getPreferredName(), parser.currentName());
token = parser.nextToken();
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
if (field.getPreferredName().equalsIgnoreCase("include")) {
return IncludeExclude.parseInclude(parser, parseContext);
} else if (field.getPreferredName().equalsIgnoreCase("exclude")) {
@ -277,7 +274,7 @@ public class IncludeExcludeTests extends ESTestCase {
builder.endObject();
XContentParser parser = createParser(builder);
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
XContentParser.Token token = parser.nextToken();
assertEquals(token, XContentParser.Token.START_OBJECT);

View File

@ -70,7 +70,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
private void assertParseSearchSource(SearchSourceBuilder testBuilder, XContentParser parser, ParseFieldMatcher pfm)
throws IOException {
QueryParseContext parseContext = new QueryParseContext(searchRequestParsers.queryParsers, parser, pfm);
QueryParseContext parseContext = new QueryParseContext(parser, pfm);
if (randomBoolean()) {
parser.nextToken(); // sometimes we move it on the START_OBJECT to
// test the embedded case
@ -83,7 +83,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
}
private QueryParseContext createParseContext(XContentParser parser) {
return new QueryParseContext(searchRequestParsers.queryParsers, parser, ParseFieldMatcher.STRICT);
return new QueryParseContext(parser, ParseFieldMatcher.STRICT);
}
public void testSerialization() throws IOException {

View File

@ -28,6 +28,7 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -46,7 +47,6 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.Field;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.Order;
@ -75,7 +75,7 @@ public class HighlightBuilderTests extends ESTestCase {
private static final int NUMBER_OF_TESTBUILDERS = 20;
private static NamedWriteableRegistry namedWriteableRegistry;
private static IndicesQueriesRegistry indicesQueriesRegistry;
private static NamedXContentRegistry xContentRegistry;
/**
* setup for the whole base test class
@ -84,13 +84,13 @@ public class HighlightBuilderTests extends ESTestCase {
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
@AfterClass
public static void afterClass() throws Exception {
namedWriteableRegistry = null;
indicesQueriesRegistry = null;
xContentRegistry = null;
}
/**
@ -129,7 +129,7 @@ public class HighlightBuilderTests extends ESTestCase {
XContentBuilder shuffled = shuffleXContent(builder);
XContentParser parser = createParser(shuffled);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
parser.nextToken();
HighlightBuilder secondHighlightBuilder;
try {
@ -170,7 +170,7 @@ public class HighlightBuilderTests extends ESTestCase {
private <T extends Throwable> T expectParseThrows(Class<T> exceptionClass, String highlightElement) throws IOException {
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
return expectThrows(exceptionClass, () -> HighlightBuilder.fromXContent(context));
}
@ -266,7 +266,7 @@ public class HighlightBuilderTests extends ESTestCase {
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings);
// shard context will only need indicesQueriesRegistry for building Query objects nested in highlighter
QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
indicesQueriesRegistry, null, null, System::currentTimeMillis) {
null, null, System::currentTimeMillis) {
@Override
public MappedFieldType fieldMapper(String name) {
TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);
@ -380,7 +380,7 @@ public class HighlightBuilderTests extends ESTestCase {
"}\n";
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context);
assertArrayEquals("setting tags_schema 'styled' should alter pre_tags", HighlightBuilder.DEFAULT_STYLED_PRE_TAG,
highlightBuilder.preTags());
@ -392,7 +392,7 @@ public class HighlightBuilderTests extends ESTestCase {
"}\n";
parser = createParser(JsonXContent.jsonXContent, highlightElement);
context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
highlightBuilder = HighlightBuilder.fromXContent(context);
assertArrayEquals("setting tags_schema 'default' should alter pre_tags", HighlightBuilder.DEFAULT_PRE_TAGS,
highlightBuilder.preTags());
@ -413,21 +413,21 @@ public class HighlightBuilderTests extends ESTestCase {
String highlightElement = "{ }";
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context);
assertEquals("expected plain HighlightBuilder", new HighlightBuilder(), highlightBuilder);
highlightElement = "{ \"fields\" : { } }";
parser = createParser(JsonXContent.jsonXContent, highlightElement);
context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
highlightBuilder = HighlightBuilder.fromXContent(context);
assertEquals("defining no field should return plain HighlightBuilder", new HighlightBuilder(), highlightBuilder);
highlightElement = "{ \"fields\" : { \"foo\" : { } } }";
parser = createParser(JsonXContent.jsonXContent, highlightElement);
context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
highlightBuilder = HighlightBuilder.fromXContent(context);
assertEquals("expected HighlightBuilder with field", new HighlightBuilder().field(new Field("foo")), highlightBuilder);
}
@ -715,4 +715,9 @@ public class HighlightBuilderTests extends ESTestCase {
private static HighlightBuilder serializedCopy(HighlightBuilder original) throws IOException {
return ESTestCase.copyWriteable(original, namedWriteableRegistry, HighlightBuilder::new);
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
}

View File

@ -164,7 +164,7 @@ public class ShardSearchTransportRequestTests extends AbstractSearchTestCase {
public QueryBuilder aliasFilter(IndexMetaData indexMetaData, String... aliasNames) {
ShardSearchRequest.FilterParser filterParser = bytes -> {
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry(), bytes)) {
return new QueryParseContext(queriesRegistry, parser, new ParseFieldMatcher(Settings.EMPTY)).parseInnerQueryBuilder();
return new QueryParseContext(parser, new ParseFieldMatcher(Settings.EMPTY)).parseInnerQueryBuilder();
}
};
return ShardSearchRequest.parseAliasFilter(filterParser, indexMetaData, aliasNames);
@ -200,7 +200,7 @@ public class ShardSearchTransportRequestTests extends AbstractSearchTestCase {
IndexSettings indexSettings = new IndexSettings(indexMetadata.build(), Settings.EMPTY);
final long nowInMillis = randomPositiveLong();
QueryShardContext context = new QueryShardContext(
0, indexSettings, null, null, null, null, null, xContentRegistry(), queriesRegistry, null, null, () -> nowInMillis);
0, indexSettings, null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
readRequest.rewrite(context);
QueryBuilder queryBuilder = readRequest.filteringAliases();
assertEquals(queryBuilder, QueryBuilders.boolQuery()

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -42,7 +43,6 @@ import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.rescore.QueryRescorer.QueryRescoreContext;
import org.elasticsearch.test.ESTestCase;
@ -59,7 +59,7 @@ public class QueryRescoreBuilderTests extends ESTestCase {
private static final int NUMBER_OF_TESTBUILDERS = 20;
private static NamedWriteableRegistry namedWriteableRegistry;
private static IndicesQueriesRegistry indicesQueriesRegistry;
private static NamedXContentRegistry xContentRegistry;
/**
* setup for the whole base test class
@ -68,13 +68,13 @@ public class QueryRescoreBuilderTests extends ESTestCase {
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
@AfterClass
public static void afterClass() throws Exception {
namedWriteableRegistry = null;
indicesQueriesRegistry = null;
xContentRegistry = null;
}
/**
@ -119,7 +119,7 @@ public class QueryRescoreBuilderTests extends ESTestCase {
XContentParser parser = createParser(shuffled);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
parser.nextToken();
RescoreBuilder<?> secondRescoreBuilder = RescoreBuilder.parseFromXContent(context);
assertNotSame(rescoreBuilder, secondRescoreBuilder);
@ -139,7 +139,7 @@ public class QueryRescoreBuilderTests extends ESTestCase {
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAsciiOfLengthBetween(1, 10), indexSettings);
// shard context will only need indicesQueriesRegistry for building Query objects nested in query rescorer
QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
indicesQueriesRegistry, null, null, () -> nowInMillis) {
null, null, () -> nowInMillis) {
@Override
public MappedFieldType fieldMapper(String name) {
TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);
@ -252,12 +252,17 @@ public class QueryRescoreBuilderTests extends ESTestCase {
*/
private QueryParseContext createContext(String rescoreElement) throws IOException {
XContentParser parser = createParser(JsonXContent.jsonXContent, rescoreElement);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
// move to first token, this is where the internal fromXContent
assertTrue(parser.nextToken() == XContentParser.Token.START_OBJECT);
return context;
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
private static RescoreBuilder<?> mutate(RescoreBuilder<?> original) throws IOException {
RescoreBuilder<?> mutation = ESTestCase.copyWriteable(original, namedWriteableRegistry, QueryRescorerBuilder::new);
if (randomBoolean()) {

View File

@ -28,14 +28,9 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.io.IOException;
import java.util.Collections;
@ -44,22 +39,6 @@ import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashC
public class SearchAfterBuilderTests extends ESTestCase {
private static final int NUMBER_OF_TESTBUILDERS = 20;
private static IndicesQueriesRegistry indicesQueriesRegistry;
/**
* setup for the whole base test class
*/
@BeforeClass
public static void init() {
indicesQueriesRegistry = new IndicesQueriesRegistry();
QueryParser<MatchAllQueryBuilder> parser = MatchAllQueryBuilder::fromXContent;
indicesQueriesRegistry.register(parser, MatchAllQueryBuilder.NAME);
}
@AfterClass
public static void afterClass() throws Exception {
indicesQueriesRegistry = null;
}
private static SearchAfterBuilder randomSearchAfterBuilder() throws IOException {
int numSearchFrom = randomIntBetween(1, 10);
@ -189,7 +168,7 @@ public class SearchAfterBuilderTests extends ESTestCase {
searchAfterBuilder.innerToXContent(builder);
builder.endObject();
XContentParser parser = createParser(shuffleXContent(builder));
new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
new QueryParseContext(parser, ParseFieldMatcher.STRICT);
parser.nextToken();
parser.nextToken();
parser.nextToken();

View File

@ -39,14 +39,9 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.UidFieldMapper;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.io.IOException;
import java.util.ArrayList;
@ -66,22 +61,6 @@ import static org.mockito.Mockito.when;
public class SliceBuilderTests extends ESTestCase {
private static final int MAX_SLICE = 20;
private static IndicesQueriesRegistry indicesQueriesRegistry;
/**
* setup for the whole base test class
*/
@BeforeClass
public static void init() {
indicesQueriesRegistry = new IndicesQueriesRegistry();
QueryParser<MatchAllQueryBuilder> parser = MatchAllQueryBuilder::fromXContent;
indicesQueriesRegistry.register(parser, MatchAllQueryBuilder.NAME);
}
@AfterClass
public static void afterClass() throws Exception {
indicesQueriesRegistry = null;
}
private static SliceBuilder randomSliceBuilder() throws IOException {
int max = randomIntBetween(2, MAX_SLICE);
@ -125,8 +104,7 @@ public class SliceBuilderTests extends ESTestCase {
sliceBuilder.innerToXContent(builder);
builder.endObject();
XContentParser parser = createParser(shuffleXContent(builder));
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser,
ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
SliceBuilder secondSliceBuilder = SliceBuilder.fromXContent(context);
assertNotSame(sliceBuilder, secondSliceBuilder);
assertEquals(sliceBuilder, secondSliceBuilder);

View File

@ -26,6 +26,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -50,7 +51,6 @@ import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
@ -77,11 +77,11 @@ import static java.util.Collections.emptyList;
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends ESTestCase {
private static final int NUMBER_OF_TESTBUILDERS = 20;
protected static NamedWriteableRegistry namedWriteableRegistry;
private static final int NUMBER_OF_TESTBUILDERS = 20;
static IndicesQueriesRegistry indicesQueriesRegistry;
private static NamedXContentRegistry xContentRegistry;
private static ScriptService scriptService;
@BeforeClass
@ -105,13 +105,13 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
@AfterClass
public static void afterClass() throws Exception {
namedWriteableRegistry = null;
indicesQueriesRegistry = null;
xContentRegistry = null;
}
/** Returns random sort that is put under test */
@ -146,7 +146,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
String elementName = itemParser.currentName();
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
T parsedItem = fromXContent(context, elementName);
assertNotSame(testItem, parsedItem);
assertEquals(testItem, parsedItem);
@ -210,7 +210,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
});
long nowInMillis = randomPositiveLong();
return new QueryShardContext(0, idxSettings, bitsetFilterCache, ifds, null, null, scriptService,
xContentRegistry(), indicesQueriesRegistry, null, null, () -> nowInMillis) {
xContentRegistry(), null, null, () -> nowInMillis) {
@Override
public MappedFieldType fieldMapper(String name) {
return provideMappedFieldType(name);
@ -235,6 +235,11 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
return doubleFieldType;
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
protected static QueryBuilder randomNestedFilter() {
int id = randomIntBetween(0, 2);
switch(id) {

View File

@ -134,7 +134,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
try {
FieldSortBuilder.fromXContent(context, "");

View File

@ -37,7 +37,6 @@ import org.elasticsearch.index.query.GeoValidationMethod;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.test.geo.RandomGeoGenerator;
@ -208,7 +207,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
try {
GeoDistanceSortBuilder.fromXContent(context, "");
@ -229,7 +228,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
try {
GeoDistanceSortBuilder.fromXContent(context, "");
@ -246,7 +245,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
try {
GeoDistanceSortBuilder item = GeoDistanceSortBuilder.fromXContent(context, "");
@ -273,7 +272,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.EMPTY);
GeoDistanceSortBuilder.fromXContent(context, "");
assertWarnings("Deprecated field [coerce] used, replaced by [validation_method]");
}
@ -292,7 +291,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.EMPTY);
GeoDistanceSortBuilder.fromXContent(context, "");
assertWarnings("Deprecated field [ignore_malformed] used, replaced by [validation_method]");
}
@ -310,7 +309,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> GeoDistanceSortBuilder.fromXContent(context, ""));
assertEquals("sort_mode [sum] isn't supported for sorting by geo distance", e.getMessage());
@ -335,7 +334,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
GeoDistanceSortBuilder result = GeoDistanceSortBuilder.fromXContent(context, json);
assertEquals("[-19.700583312660456, -2.8225036337971687, "
@ -457,7 +456,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
private GeoDistanceSortBuilder parse(XContentBuilder sortBuilder) throws Exception {
XContentParser parser = createParser(sortBuilder);
QueryParseContext parseContext = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
QueryParseContext parseContext = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
parser.nextToken();
return GeoDistanceSortBuilder.fromXContent(parseContext, null);
}

View File

@ -22,7 +22,6 @@ package org.elasticsearch.search.sort;
import org.apache.lucene.search.SortField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.QueryParseContext;
@ -69,7 +68,7 @@ public class ScoreSortBuilderTests extends AbstractSortTestCase<ScoreSortBuilder
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ScoreSortBuilder scoreSort = ScoreSortBuilder.fromXContent(context, "_score");
assertEquals(order, scoreSort.order());
}
@ -82,7 +81,7 @@ public class ScoreSortBuilderTests extends AbstractSortTestCase<ScoreSortBuilder
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.EMPTY);
try {
ScoreSortBuilder.fromXContent(context, "_score");

View File

@ -172,7 +172,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ScriptSortBuilder builder = ScriptSortBuilder.fromXContent(context, null);
assertEquals("doc['field_name'].value * factor", builder.script().getIdOrCode());
assertEquals(Script.DEFAULT_SCRIPT_LANG, builder.script().getLang());
@ -198,7 +198,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
ScriptSortBuilder builder = ScriptSortBuilder.fromXContent(context, null);
assertEquals("doc['field_name'].value", builder.script().getIdOrCode());
assertEquals(Script.DEFAULT_SCRIPT_LANG, builder.script().getLang());
@ -218,7 +218,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
Exception e = expectThrows(IllegalArgumentException.class, () -> ScriptSortBuilder.fromXContent(context, null));
assertEquals("[_script] unknown field [bad_field], parser not found", e.getMessage());
}
@ -231,7 +231,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
Exception e = expectThrows(IllegalArgumentException.class, () -> ScriptSortBuilder.fromXContent(context, null));
assertEquals("[_script] unknown field [bad_field], parser not found", e.getMessage());
}
@ -243,7 +243,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
parser.nextToken();
parser.nextToken();
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
Exception e = expectThrows(IllegalArgumentException.class, () -> ScriptSortBuilder.fromXContent(context, null));
assertEquals("[_script] script doesn't support values of type: START_ARRAY", e.getMessage());
}

View File

@ -21,15 +21,14 @@ package org.elasticsearch.search.sort;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass;
@ -43,24 +42,19 @@ import java.util.List;
import static java.util.Collections.emptyList;
public class SortBuilderTests extends ESTestCase {
private static final int NUMBER_OF_RUNS = 20;
protected static NamedWriteableRegistry namedWriteableRegistry;
static IndicesQueriesRegistry indicesQueriesRegistry;
private static NamedXContentRegistry xContentRegistry;
@BeforeClass
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
@AfterClass
public static void afterClass() throws Exception {
namedWriteableRegistry = null;
indicesQueriesRegistry = null;
xContentRegistry = null;
}
/**
@ -237,9 +231,14 @@ public class SortBuilderTests extends ESTestCase {
assertEquals(new ScoreSortBuilder(), result.get(5));
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return xContentRegistry;
}
private List<SortBuilder<?>> parseSort(String jsonString) throws IOException {
XContentParser itemParser = createParser(JsonXContent.jsonXContent, jsonString);
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(itemParser, ParseFieldMatcher.STRICT);
assertEquals(XContentParser.Token.START_OBJECT, itemParser.nextToken());
assertEquals(XContentParser.Token.FIELD_NAME, itemParser.nextToken());

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass;
@ -44,7 +43,6 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
private static final int NUMBER_OF_TESTBUILDERS = 20;
protected static NamedWriteableRegistry namedWriteableRegistry;
protected static IndicesQueriesRegistry queriesRegistry;
protected static ParseFieldMatcher parseFieldMatcher;
protected static Suggesters suggesters;
@ -55,7 +53,6 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
public static void init() throws IOException {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
queriesRegistry = searchModule.getQueryParserRegistry();
suggesters = searchModule.getSuggesters();
parseFieldMatcher = ParseFieldMatcher.STRICT;
}
@ -64,7 +61,6 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
public static void afterClass() throws Exception {
namedWriteableRegistry = null;
suggesters = null;
queriesRegistry = null;
}
/**
@ -128,7 +124,7 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
XContentBuilder shuffled = shuffleXContent(xContentBuilder, shuffleProtectedFields());
XContentParser parser = createParser(shuffled);
QueryParseContext context = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
QueryParseContext context = new QueryParseContext(parser, parseFieldMatcher);
// we need to skip the start object and the name, those will be parsed by outer SuggestBuilder
parser.nextToken();
@ -191,7 +187,7 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
}
protected static QueryParseContext newParseContext(XContentParser parser) throws IOException {
final QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
final QueryParseContext parseContext = new QueryParseContext(parser, parseFieldMatcher);
return parseContext;
}
}

View File

@ -25,11 +25,9 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.suggest.completion.CompletionSuggesterBuilderTests;
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilderTests;
@ -78,7 +76,7 @@ public class SuggestBuilderTests extends ESTestCase {
}
suggestBuilder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
XContentParser parser = createParser(xContentBuilder);
QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
SuggestBuilder secondSuggestBuilder = SuggestBuilder.fromXContent(context, suggesters);
assertNotSame(suggestBuilder, secondSuggestBuilder);
assertEquals(suggestBuilder, secondSuggestBuilder);

View File

@ -34,7 +34,6 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.suggest.completion.context.CategoryContextMapping;
import org.elasticsearch.search.suggest.completion.context.ContextBuilder;
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
@ -258,7 +257,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
}
private static QueryParseContext createParseContext(XContentParser parser) {
return new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
return new QueryParseContext(parser, ParseFieldMatcher.STRICT);
}
public void testQueryContextParsingMixed() throws Exception {

View File

@ -30,7 +30,6 @@ import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.suggest.completion.context.ContextBuilder;
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
import org.elasticsearch.search.suggest.completion.context.GeoContextMapping;
@ -352,6 +351,6 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
}
private static QueryParseContext createParseContext(XContentParser parser) {
return new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
return new QueryParseContext(parser, ParseFieldMatcher.STRICT);
};
}

View File

@ -20,13 +20,11 @@
package org.elasticsearch.search.suggest.completion;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
@ -52,7 +50,7 @@ public abstract class QueryContextTestCase<QC extends ToXContent> extends ESTest
toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = createParser(builder);
parser.nextToken();
QC fromXContext = fromXContent(new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT));
QC fromXContext = fromXContent(new QueryParseContext(parser, ParseFieldMatcher.STRICT));
assertEquals(toXContent, fromXContext);
assertEquals(toXContent.hashCode(), fromXContext.hashCode());
}

View File

@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionContext.DirectCandidateGenerator;
import org.elasticsearch.test.ESTestCase;
@ -42,13 +41,9 @@ import java.util.function.Supplier;
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
public class DirectCandidateGeneratorTests extends ESTestCase{
private static final IndicesQueriesRegistry mockRegistry = new IndicesQueriesRegistry();
public class DirectCandidateGeneratorTests extends ESTestCase {
private static final int NUMBER_OF_RUNS = 20;
/**
* Test serialization and deserialization of the generator
*/
@ -113,7 +108,7 @@ public class DirectCandidateGeneratorTests extends ESTestCase{
}
generator.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = createParser(shuffleXContent(builder));
QueryParseContext context = new QueryParseContext(mockRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
parser.nextToken();
DirectCandidateGeneratorBuilder secondGenerator = DirectCandidateGeneratorBuilder.fromXContent(context);
assertNotSame(generator, secondGenerator);
@ -177,7 +172,7 @@ public class DirectCandidateGeneratorTests extends ESTestCase{
private void assertIllegalXContent(String directGenerator, Class<? extends Exception> exceptionClass, String exceptionMsg)
throws IOException {
XContentParser parser = createParser(JsonXContent.jsonXContent, directGenerator);
QueryParseContext context = new QueryParseContext(mockRegistry, parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
Exception e = expectThrows(exceptionClass, () -> DirectCandidateGeneratorBuilder.fromXContent(context));
assertEquals(exceptionMsg, e.getMessage());
}

View File

@ -39,7 +39,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass;
@ -99,7 +98,7 @@ public abstract class SmoothingModelTestCase extends ESTestCase {
testModel.innerToXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
XContentParser parser = createParser(shuffleXContent(contentBuilder));
QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
QueryParseContext context = new QueryParseContext(parser, ParseFieldMatcher.STRICT);
parser.nextToken(); // go to start token, real parsing would do that in the outer element parser
SmoothingModel parsedModel = fromXContent(context);
assertNotSame(testModel, parsedModel);

View File

@ -88,7 +88,7 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
try (XContentParser parser = XContentFactory.xContent(source).createParser(xContentRegistry, source)) {
SearchSourceBuilder builder = SearchSourceBuilder.searchSource();
builder.parseXContent(new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher),
builder.parseXContent(new QueryParseContext(parser, parseFieldMatcher),
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
builder.explain(request.isExplain());
builder.profile(request.isProfile());

View File

@ -160,7 +160,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
BytesReference docSource = getResponseSources.get(i);
try {
SearchRequest searchRequest = TransportPercolateAction.createSearchRequest(
percolateRequest, docSource, searchRequestParsers.queryParsers,
percolateRequest, docSource,
searchRequestParsers.aggParsers, searchRequestParsers.searchExtParsers, xContentRegistry, parseFieldMatcher);
multiSearchRequest.add(searchRequest);
} catch (Exception e) {

View File

@ -45,7 +45,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchExtRegistry;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
@ -107,7 +106,7 @@ public class TransportPercolateAction extends HandledTransportAction<PercolateRe
private void innerDoExecute(PercolateRequest request, BytesReference docSource, ActionListener<PercolateResponse> listener) {
SearchRequest searchRequest;
try {
searchRequest = createSearchRequest(request, docSource, searchRequestParsers.queryParsers,
searchRequest = createSearchRequest(request, docSource,
searchRequestParsers.aggParsers, searchRequestParsers.searchExtParsers, xContentRegistry, parseFieldMatcher);
} catch (IOException e) {
listener.onFailure(e);
@ -131,7 +130,7 @@ public class TransportPercolateAction extends HandledTransportAction<PercolateRe
}
public static SearchRequest createSearchRequest(PercolateRequest percolateRequest, BytesReference documentSource,
IndicesQueriesRegistry queryRegistry, AggregatorParsers aggParsers,
AggregatorParsers aggParsers,
SearchExtRegistry searchExtRegistry, NamedXContentRegistry xContentRegistry,
ParseFieldMatcher parseFieldMatcher)
throws IOException {
@ -214,7 +213,7 @@ public class TransportPercolateAction extends HandledTransportAction<PercolateRe
new PercolateQueryBuilder("query", percolateRequest.documentType(), documentSource);
if (querySource != null) {
try (XContentParser parser = XContentHelper.createParser(xContentRegistry, querySource)) {
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry, parser, parseFieldMatcher);
QueryParseContext queryParseContext = new QueryParseContext(parser, parseFieldMatcher);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(queryParseContext.parseInnerQueryBuilder());
boolQueryBuilder.filter(percolateQueryBuilder);
@ -232,7 +231,7 @@ public class TransportPercolateAction extends HandledTransportAction<PercolateRe
BytesReference source = searchSource.bytes();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(xContentRegistry, source)) {
QueryParseContext context = new QueryParseContext(queryRegistry, parser, parseFieldMatcher);
QueryParseContext context = new QueryParseContext(parser, parseFieldMatcher);
searchSourceBuilder.parseXContent(context, aggParsers, null, searchExtRegistry);
searchRequest.source(searchSourceBuilder);
return searchRequest;

View File

@ -233,7 +233,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
}
QueryParseContext queryParseContext(XContentParser parser) {
return new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher);
return new QueryParseContext(parser, parseFieldMatcher);
}
@Override

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.reindex.RestReindexAction.ReindexParseContext;
import org.elasticsearch.index.reindex.remote.RemoteInfo;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.ESTestCase;
@ -125,7 +124,7 @@ public class RestReindexActionTests extends ESTestCase {
}
try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
SearchRequestParsers searchParsers = new SearchRequestParsers(new IndicesQueriesRegistry(), null, null, null);
SearchRequestParsers searchParsers = new SearchRequestParsers(null, null, null);
RestReindexAction.PARSER.parse(p, r, new ReindexParseContext(searchParsers, ParseFieldMatcher.STRICT));
assertEquals("localhost", r.getRemoteInfo().getHost());
assertArrayEquals(new String[] {"source"}, r.getSearchRequest().indices());
@ -133,7 +132,7 @@ public class RestReindexActionTests extends ESTestCase {
}
public void testPipelineQueryParameterIsError() throws IOException {
SearchRequestParsers parsers = new SearchRequestParsers(new IndicesQueriesRegistry(), null, null, null);
SearchRequestParsers parsers = new SearchRequestParsers(null, null, null);
RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class), parsers, null);
FakeRestRequest.Builder request = new FakeRestRequest.Builder(xContentRegistry());

View File

@ -83,7 +83,6 @@ import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.node.internal.InternalSettingsPreparer;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
@ -779,7 +778,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
* @return a new {@link QueryParseContext} based on the base test index and queryParserService
*/
protected static QueryParseContext createParseContext(XContentParser parser, ParseFieldMatcher matcher) {
return new QueryParseContext(serviceHolder.indicesQueriesRegistry, parser, matcher);
return new QueryParseContext(parser, matcher);
}
/**
@ -1013,8 +1012,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
}
private static class ServiceHolder implements Closeable {
private final IndicesQueriesRegistry indicesQueriesRegistry;
private final IndexFieldDataService indexFieldDataService;
private final SearchModule searchModule;
private final NamedWriteableRegistry namedWriteableRegistry;
@ -1075,7 +1072,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
}
});
indicesQueriesRegistry = searchModule.getQueryParserRegistry();
for (String type : currentTypes) {
mapperService.merge(type, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(type,
@ -1106,7 +1102,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
QueryShardContext createShardContext() {
return new QueryShardContext(0, idxSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService,
scriptService, xContentRegistry, indicesQueriesRegistry, this.client, null, () -> nowInMillis);
scriptService, xContentRegistry, this.client, null, () -> nowInMillis);
}
ScriptModule createScriptModule(List<ScriptPlugin> scriptPlugins) {

View File

@ -35,7 +35,7 @@ public class MockSearchServiceTests extends ESTestCase {
public void testAssertNoInFlightContext() {
final long nowInMillis = randomPositiveLong();
SearchContext s = new TestSearchContext(new QueryShardContext(0, new IndexSettings(IndexMetaData.PROTO, Settings.EMPTY), null, null,
null, null, null, xContentRegistry(), null, null, null, () -> nowInMillis)) {
null, null, null, xContentRegistry(), null, null, () -> nowInMillis)) {
@Override
public SearchShardTarget shardTarget() {
return new SearchShardTarget("node", new Index("idx", "ignored"), 0);