diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 3a11dd64fbd..7c3caf09c7d 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -254,7 +254,6 @@ public class IndexShard extends AbstractIndexShardComponent { cachingPolicy = new UsageTrackingQueryCachingPolicy(); } this.engineConfig = newEngineConfig(translogConfig, cachingPolicy); - this.indexShardOperationCounter = new IndexShardOperationCounter(logger, shardId); } @@ -324,6 +323,10 @@ public class IndexShard extends AbstractIndexShardComponent { return this.shardRouting; } + public QueryCachingPolicy getQueryCachingPolicy() { + return this.engineConfig.getQueryCachingPolicy(); + } + /** * Updates the shards routing entry. This mutate the shards internal state depending * on the changes that get introduced by the new routing value. This method will persist shard level metadata diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 64b8b273cca..ff477f6ec26 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -372,9 +372,10 @@ public class SearchService extends AbstractLifecycleComponent { public QuerySearchResult executeQueryPhase(QuerySearchRequest request) { final SearchContext context = findContext(request.id()); contextProcessing(context); + IndexShard indexShard = context.indexShard(); try { - final IndexCache indexCache = context.indexShard().indexService().cache(); - final QueryCachingPolicy cachingPolicy = context.indexShard().engine().config().getQueryCachingPolicy(); + final IndexCache indexCache = indexShard.indexService().cache(); + final QueryCachingPolicy cachingPolicy = indexShard.getQueryCachingPolicy(); context.searcher().dfSource(new CachedDfSource(context.searcher().getIndexReader(), request.dfs(), context.similarityService().similarity(), indexCache.query(), cachingPolicy)); } catch (Throwable e) { @@ -382,7 +383,7 @@ public class SearchService extends AbstractLifecycleComponent { cleanContext(context); throw new QueryPhaseExecutionException(context, "Failed to set aggregated df", e); } - ShardSearchStats shardSearchStats = context.indexShard().searchService(); + ShardSearchStats shardSearchStats = indexShard.searchService(); try { shardSearchStats.onPreQueryPhase(context); long time = System.nanoTime(); @@ -448,8 +449,9 @@ public class SearchService extends AbstractLifecycleComponent { final SearchContext context = findContext(request.id()); contextProcessing(context); try { - final IndexCache indexCache = context.indexShard().indexService().cache(); - final QueryCachingPolicy cachingPolicy = context.indexShard().engine().config().getQueryCachingPolicy(); + final IndexShard indexShard = context.indexShard(); + final IndexCache indexCache = indexShard.indexService().cache(); + final QueryCachingPolicy cachingPolicy = indexShard.getQueryCachingPolicy(); context.searcher().dfSource(new CachedDfSource(context.searcher().getIndexReader(), request.dfs(), context.similarityService().similarity(), indexCache.query(), cachingPolicy)); } catch (Throwable e) {