From 567c65b0d57e92cd530dafa7f55de7ba681af13e Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 21 Dec 2016 09:05:14 -0500 Subject: [PATCH] Replace IndicesQueriesRegistry (#22289) * Switch query parsing to namedObject * Remove IndicesQueriesRegistry --- .../org/elasticsearch/index/IndexModule.java | 4 +- .../org/elasticsearch/index/IndexService.java | 6 +- .../index/query/MatchAllQueryBuilder.java | 2 +- .../index/query/QueryParseContext.java | 22 ++++--- .../index/query/QueryRewriteContext.java | 7 +-- .../index/query/QueryShardContext.java | 9 +-- .../elasticsearch/indices/IndicesService.java | 18 +----- .../indices/query/IndicesQueriesRegistry.java | 32 ----------- .../java/org/elasticsearch/node/Node.java | 4 +- .../rest/action/RestActions.java | 6 +- .../indices/RestValidateQueryAction.java | 12 +--- .../rest/action/cat/RestCountAction.java | 9 +-- .../rest/action/document/RestCountAction.java | 11 +--- .../rest/action/search/RestExplainAction.java | 9 +-- .../action/search/RestMultiSearchAction.java | 3 +- .../rest/action/search/RestSearchAction.java | 2 +- .../elasticsearch/search/SearchModule.java | 57 ++++++++++--------- .../search/SearchRequestParsers.java | 14 +---- .../search/MultiSearchRequestTests.java | 17 +++--- .../elasticsearch/index/IndexModuleTests.java | 5 +- .../index/mapper/DateFieldTypeTests.java | 10 ++-- .../index/mapper/RangeFieldTypeTests.java | 2 +- .../index/query/BoolQueryBuilderTests.java | 1 - .../index/query/InnerHitBuilderTests.java | 15 +++-- .../index/query/QueryParseContextTests.java | 28 +++++---- .../index/query/QueryShardContextTests.java | 2 +- .../index/query/RangeQueryRewriteTests.java | 6 +- .../index/query/SimpleQueryParserTests.java | 26 +-------- .../search/AbstractSearchTestCase.java | 11 +++- .../search/SearchModuleTests.java | 50 +++++++--------- .../AggregationCollectorTests.java | 4 +- .../aggregations/AggregatorParsingTests.java | 25 ++++---- .../aggregations/BaseAggregationTestCase.java | 13 +++-- .../BasePipelineAggregationTestCase.java | 5 +- .../geogrid/GeoHashGridParserTests.java | 14 ++--- .../bucket/histogram/ExtendedBoundsTests.java | 2 +- .../SignificanceHeuristicTests.java | 7 +-- .../aggregations/metrics/FiltersTests.java | 8 +-- .../aggregations/metrics/TopHitsTests.java | 5 +- .../ExtendedStatsBucketTests.java | 2 +- .../bucketmetrics/PercentilesBucketTests.java | 2 +- .../pipeline/moving/avg/MovAvgTests.java | 2 +- .../support/IncludeExcludeTests.java | 7 +-- .../builder/SearchSourceBuilderTests.java | 4 +- .../highlight/HighlightBuilderTests.java | 29 ++++++---- .../ShardSearchTransportRequestTests.java | 4 +- .../rescore/QueryRescoreBuilderTests.java | 19 ++++--- .../searchafter/SearchAfterBuilderTests.java | 23 +------- .../search/slice/SliceBuilderTests.java | 24 +------- .../search/sort/AbstractSortTestCase.java | 19 ++++--- .../search/sort/FieldSortBuilderTests.java | 2 +- .../sort/GeoDistanceSortBuilderTests.java | 17 +++--- .../search/sort/ScoreSortBuilderTests.java | 5 +- .../search/sort/ScriptSortBuilderTests.java | 10 ++-- .../search/sort/SortBuilderTests.java | 21 ++++--- .../AbstractSuggestionBuilderTestCase.java | 8 +-- .../search/suggest/SuggestBuilderTests.java | 4 +- .../CategoryContextMappingTests.java | 3 +- .../completion/GeoContextMappingTests.java | 3 +- .../completion/QueryContextTestCase.java | 4 +- .../phrase/DirectCandidateGeneratorTests.java | 11 +--- .../phrase/SmoothingModelTestCase.java | 3 +- .../TransportSearchTemplateAction.java | 2 +- .../TransportMultiPercolateAction.java | 2 +- .../percolator/TransportPercolateAction.java | 9 ++- .../index/reindex/RestReindexAction.java | 2 +- .../index/reindex/RestReindexActionTests.java | 5 +- .../test/AbstractQueryTestCase.java | 8 +-- .../search/MockSearchServiceTests.java | 2 +- 69 files changed, 282 insertions(+), 457 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/indices/query/IndicesQueriesRegistry.java diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index 3734a4eab58..97edd2fd468 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -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); } diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index 11018d75b3b..32a0268e3ea 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -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); } diff --git a/core/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java index 4a86854e7bf..63580eca3e7 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java @@ -58,7 +58,7 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder PARSER = new ObjectParser<>(NAME, MatchAllQueryBuilder::new); + private static final ObjectParser PARSER = new ObjectParser<>(NAME, MatchAllQueryBuilder::new); static { declareStandardFields(PARSER); diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index b944bd3a42c..c8b0e1cb672 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -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(), diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java index e98af78cf24..13362f676aa 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java @@ -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() { diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index a4a1193063b..31668922e6e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -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 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(); } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 413af6466db..8f5d01d7683 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -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); diff --git a/core/src/main/java/org/elasticsearch/indices/query/IndicesQueriesRegistry.java b/core/src/main/java/org/elasticsearch/indices/query/IndicesQueriesRegistry.java deleted file mode 100644 index f1d45b55495..00000000000 --- a/core/src/main/java/org/elasticsearch/indices/query/IndicesQueriesRegistry.java +++ /dev/null @@ -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> { - public IndicesQueriesRegistry() { - super("query"); - } -} diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index bfe5ad453b5..2c29d00ecc6 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -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); diff --git a/core/src/main/java/org/elasticsearch/rest/action/RestActions.java b/core/src/main/java/org/elasticsearch/rest/action/RestActions.java index 0cb1a248b17..4a96becbbbd 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/RestActions.java +++ b/core/src/main/java/org/elasticsearch/rest/action/RestActions.java @@ -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(); } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java index 8b68a3b6168..e12baa35bec 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java @@ -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)); } diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java index 22346ad2772..49cbcfa6610 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java @@ -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) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java b/core/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java index 2983879961c..86acb1fb1b9 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java @@ -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")); diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java index 7d31ed7cad5..a3c845555bf 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java @@ -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); diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 502d427050f..95c8ed51a3f 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -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); diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 425acbf41e3..b0e0ce074cf 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -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); } diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index a5ea15c6702..41b59e6d686 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -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 highlighters; private final Map> suggesters; - private final IndicesQueriesRegistry queryParserRegistry = new IndicesQueriesRegistry(); private final ParseFieldRegistry aggregationParserRegistry = new ParseFieldRegistry<>("aggregation"); private final ParseFieldRegistry 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 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> t : spec.getResultReaders().entrySet()) { String writeableName = t.getKey(); Writeable.Reader 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> 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 void registerFromPlugin(List plugins, Function> producer, Consumer consumer) { @@ -568,9 +566,9 @@ public class SearchModule { } public static void registerSmoothingModels(List 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> setupSuggesters(List 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 reader) { - namedWriteables.add(new Entry(DocValueFormat.class, name, reader)); + namedWriteables.add(new NamedWriteableRegistry.Entry(DocValueFormat.class, name, reader)); } private void registerSignificanceHeuristics(List plugins) { @@ -662,7 +660,8 @@ public class SearchModule { private void registerSignificanceHeuristic(SearchExtensionSpec 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 plugins) { @@ -677,7 +676,8 @@ public class SearchModule { private void registerMovingAverageModel(SearchExtensionSpec 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 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() { diff --git a/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java b/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java index ba3afc15771..085f55ad71f 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java +++ b/core/src/main/java/org/elasticsearch/search/SearchRequestParsers.java @@ -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; diff --git a/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java b/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java index e42c56046e6..cdaae6aa0ff 100644 --- a/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java @@ -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 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)))); } } diff --git a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java index e9b52589b9c..46281c812f1 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -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)); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java index a93cf0153cf..15f1819e939 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java @@ -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"; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java index da822349909..04f5dcb5b91 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java @@ -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); diff --git a/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java index 13854ffc1e2..ab73551d3e1 100644 --- a/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java @@ -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; diff --git a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java index 9c021e249a8..6b9fbe76ba8 100644 --- a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java @@ -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)); diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java index da76c2796f6..1e00176f558 100644 --- a/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java @@ -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; + } } diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryShardContextTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryShardContextTests.java index ccf514dd41c..434c3d1ebf3 100644 --- a/core/src/test/java/org/elasticsearch/index/query/QueryShardContextTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/QueryShardContextTests.java @@ -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); diff --git a/core/src/test/java/org/elasticsearch/index/query/RangeQueryRewriteTests.java b/core/src/test/java/org/elasticsearch/index/query/RangeQueryRewriteTests.java index 607f3f924d3..d7ef534bcb2 100644 --- a/core/src/test/java/org/elasticsearch/index/query/RangeQueryRewriteTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/RangeQueryRewriteTests.java @@ -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)); diff --git a/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java b/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java index 2d7809b7df6..3c9b0f29d75 100644 --- a/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java @@ -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 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) { diff --git a/core/src/test/java/org/elasticsearch/search/AbstractSearchTestCase.java b/core/src/test/java/org/elasticsearch/search/AbstractSearchTestCase.java index cf290b2b1b6..310ad86eb11 100644 --- a/core/src/test/java/org/elasticsearch/search/AbstractSearchTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/AbstractSearchTestCase.java @@ -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() { diff --git a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java index 2e9644191f6..89e846bdb8b 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java @@ -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 getAggregations() { @@ -200,31 +197,22 @@ public class SearchModuleTests extends ModuleTestCase { } public void testRegisteredQueries() throws IOException { - SearchModule module = new SearchModule(Settings.EMPTY, false, emptyList()); List 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 registeredNonDeprecated = module.getNamedXContents().stream() + .filter(e -> e.categoryClass.equals(QueryBuilder.class)) + .map(e -> e.name.getPreferredName()) + .collect(toSet()); + Set 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() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java index c81ec476b86..0e79655d828 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java @@ -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); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index 26b3dd6f8f2..5d6222e6979 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -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; + } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index e8073bac354..a39a17068f5 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -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 now); + null, xContentRegistry(), null, null, () -> now); when(context.getQueryShardContext()).thenReturn(qsc); FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime"); DocValueFormat format = new DocValueFormat.DateTime(formatter, DateTimeZone.UTC); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java index 655a03a75c0..0db3fd6aa3f 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java @@ -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 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 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( diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java index 496e77f364c..bf8e7421747 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java @@ -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 T expectParseThrows(Class 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; + } } diff --git a/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java b/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java index 76474422961..1ac267330d7 100644 --- a/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java +++ b/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java @@ -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() diff --git a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java index 160e5393391..3e051c9828b 100644 --- a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java @@ -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()) { diff --git a/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java b/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java index beb69a0184b..93663d93683 100644 --- a/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java @@ -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 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(); diff --git a/core/src/test/java/org/elasticsearch/search/slice/SliceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/slice/SliceBuilderTests.java index 52bc3bd4633..a51fc8d412f 100644 --- a/core/src/test/java/org/elasticsearch/search/slice/SliceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/slice/SliceBuilderTests.java @@ -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 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); diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index 63e65a91062..683d5d78c9e 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -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> 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> 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> 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> 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> extends EST return doubleFieldType; } + @Override + protected NamedXContentRegistry xContentRegistry() { + return xContentRegistry; + } + protected static QueryBuilder randomNestedFilter() { int id = randomIntBetween(0, 2); switch(id) { diff --git a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java index 60b9f14c368..bb9761c0f26 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java @@ -134,7 +134,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase 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 ScriptSortBuilder.fromXContent(context, null)); assertEquals("[_script] unknown field [bad_field], parser not found", e.getMessage()); } @@ -231,7 +231,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase ScriptSortBuilder.fromXContent(context, null)); assertEquals("[_script] unknown field [bad_field], parser not found", e.getMessage()); } @@ -243,7 +243,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase ScriptSortBuilder.fromXContent(context, null)); assertEquals("[_script] script doesn't support values of type: START_ARRAY", e.getMessage()); } diff --git a/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java index d31dee0b3d2..b521060f27e 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java @@ -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> 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()); diff --git a/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java b/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java index 0f93e6a36e5..f75b73a5138 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java @@ -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 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()); } diff --git a/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java b/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java index 27ec964aa4b..eab93d9fbdf 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java @@ -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 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()); } diff --git a/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java b/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java index 044982540a3..b8289c70062 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java @@ -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); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java index 0342747b6b9..2ad36f3d1dc 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java @@ -88,7 +88,7 @@ public class TransportSearchTemplateAction extends HandledTransportAction 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> * @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> } 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> } }); - indicesQueriesRegistry = searchModule.getQueryParserRegistry(); for (String type : currentTypes) { mapperService.merge(type, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(type, @@ -1106,7 +1102,7 @@ public abstract class AbstractQueryTestCase> 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 scriptPlugins) { diff --git a/test/framework/src/test/java/org/elasticsearch/search/MockSearchServiceTests.java b/test/framework/src/test/java/org/elasticsearch/search/MockSearchServiceTests.java index b000c42d41a..2542e1c374b 100644 --- a/test/framework/src/test/java/org/elasticsearch/search/MockSearchServiceTests.java +++ b/test/framework/src/test/java/org/elasticsearch/search/MockSearchServiceTests.java @@ -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);