From 968561ad49714efe1312835a0ea0052d1a25372d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 3 Nov 2015 17:09:32 +0100 Subject: [PATCH] apply review comments --- .../validate/query/TransportValidateQueryAction.java | 4 ++-- .../main/java/org/elasticsearch/index/IndexSettings.java | 6 +++++- .../index/percolator/PercolatorQueriesRegistry.java | 2 +- .../org/elasticsearch/index/query/QueryShardContext.java | 7 ++++++- .../elasticsearch/index/query/TemplateQueryBuilder.java | 2 +- .../org/elasticsearch/index/query/WrapperQueryBuilder.java | 2 +- .../java/org/elasticsearch/indices/IndicesService.java | 7 +++++-- .../main/java/org/elasticsearch/search/SearchService.java | 5 +++-- .../elasticsearch/index/query/AbstractQueryTestCase.java | 2 +- .../index/query/WrapperQueryBuilderTests.java | 2 +- 10 files changed, 26 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index 2b8844d8d13..326dbc01289 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -163,7 +163,7 @@ public class TransportValidateQueryAction extends TransportBroadcastActiontrue if the given expression matches the index name or one of it's aliases + */ + public boolean matchesIndexName(String expression) { return indexNameMatcher.test(expression); } + /** * Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed. * diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java index ba08679716e..c7e4dbcaaee 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java @@ -179,7 +179,7 @@ public final class PercolatorQueriesRegistry extends AbstractIndexShardComponent if (type != null) { previousTypes = QueryShardContext.setTypesWithPrevious(type); } - QueryShardContext context = queryShardContext.clone(); + QueryShardContext context = new QueryShardContext(queryShardContext); try { context.reset(parser); // This means that fields in the query need to exist in the mapping prior to registering this query 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 1b6c2d7582c..65dfb559e3f 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -123,6 +123,11 @@ public class QueryShardContext { this.parseContext = new QueryParseContext(indicesQueriesRegistry); } + public QueryShardContext(QueryShardContext source) { + this(source.indexSettings, source.client, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService, source.similarityService, source.scriptService, source.indicesQueriesRegistry); + } + + public QueryShardContext clone() { return new QueryShardContext(indexSettings, client, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry); } @@ -348,7 +353,7 @@ public class QueryShardContext { public boolean matchesIndices(String... indices) { for (String index : indices) { - if (indexSettings.isMatchIndexName(index)) { + if (indexSettings.matchesIndexName(index)) { return true; } } diff --git a/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java index 6f5d00b4f73..2cecc4e2b0d 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java @@ -102,7 +102,7 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder result = contextCopy.parseContext().parseInnerQueryBuilder(); diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 549c79a59b4..bb1ed717028 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -799,7 +799,10 @@ public class IndicesService extends AbstractLifecycleComponent i } } - public QueryParseContext newQueryParserContext() { - return new QueryParseContext(indicesQueriesRegistry); + /** + * Returns this nodes {@link IndicesQueriesRegistry} + */ + public IndicesQueriesRegistry getIndicesQueryRegistry() { + return indicesQueriesRegistry; } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index a7a35f57849..9501099997f 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -551,6 +551,7 @@ public class SearchService extends AbstractLifecycleComponent imp SearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, defaultSearchTimeout); SearchContext.setCurrent(context); + try { if (request.scroll() != null) { context.scrollContext(new ScrollContext()); @@ -560,7 +561,7 @@ public class SearchService extends AbstractLifecycleComponent imp ExecutableScript executable = this.scriptService.executable(request.template(), ScriptContext.Standard.SEARCH, context); BytesReference run = (BytesReference) executable.run(); try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) { - QueryParseContext queryParseContext = indicesService.newQueryParserContext(); + QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry()); queryParseContext.reset(parser); queryParseContext.parseFieldMatcher(parseFieldMatcher); parseSource(context, SearchSourceBuilder.parseSearchSource(parser, queryParseContext)); @@ -1180,7 +1181,7 @@ public class SearchService extends AbstractLifecycleComponent imp try { long now = System.nanoTime(); final IndexService indexService = indicesService.indexServiceSafe(indexShard.shardId().index().name()); - QueryParseContext queryParseContext = indicesService.newQueryParserContext(); + QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry()); queryParseContext.parseFieldMatcher(indexService.getIndexSettings().getParseFieldMatcher()); ShardSearchRequest request = new ShardSearchLocalRequest(indexShard.shardId(), indexShard.getIndexSettings() .getNumberOfShards(), diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index 29bcbf6d96d..788c3ca3324 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -577,7 +577,7 @@ public abstract class AbstractQueryTestCase> * @return a new {@link QueryShardContext} based on the base test index and queryParserService */ protected static QueryShardContext createShardContext() { - QueryShardContext queryCreationContext = queryShardContext.clone(); + QueryShardContext queryCreationContext = new QueryShardContext(queryShardContext); queryCreationContext.reset(); queryCreationContext.parseFieldMatcher(ParseFieldMatcher.STRICT); return queryCreationContext; diff --git a/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java index a36ddd14e8b..3771cd71526 100644 --- a/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java @@ -56,7 +56,7 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase innerQuery = contextCopy.parseContext().parseInnerQueryBuilder(); Query expected = innerQuery.toQuery(context);