Skip to content

Commit e88b7fd

Browse files
committed
call createWeight on the query rather the searcher in order to avoid query caching
1 parent 9ef8948 commit e88b7fd

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

server/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java

+1-18
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,6 @@ public class ContextIndexSearcher extends IndexSearcher {
6767
*/
6868
private static int CHECK_CANCELLED_SCORER_INTERVAL = 1 << 11;
6969

70-
/**
71-
* A policy to bypass the cache entirely
72-
*/
73-
private static final QueryCachingPolicy NEVER_CACHE_POLICY = new QueryCachingPolicy() {
74-
@Override
75-
public void onUse(Query query) {}
76-
77-
@Override
78-
public boolean shouldCache(Query query) {
79-
return false;
80-
}
81-
};
82-
8370
private AggregatedDfs aggregatedDfs;
8471
private QueryProfiler profiler;
8572
private Runnable checkCancelled;
@@ -92,10 +79,6 @@ public ContextIndexSearcher(IndexReader reader, Similarity similarity, QueryCach
9279
}
9380

9481
public void setProfiler(QueryProfiler profiler) {
95-
if (profiler != null) {
96-
// disable query caching on profiled query
97-
setQueryCachingPolicy(NEVER_CACHE_POLICY);
98-
}
9982
this.profiler = profiler;
10083
}
10184

@@ -137,7 +120,7 @@ public Weight createWeight(Query query, ScoreMode scoreMode, float boost) throws
137120
timer.start();
138121
final Weight weight;
139122
try {
140-
weight = super.createWeight(query, scoreMode, boost);
123+
weight = query.createWeight(this, scoreMode, boost);
141124
} finally {
142125
timer.stop();
143126
profiler.pollLastElement();

server/src/test/java/org/elasticsearch/indices/IndicesRequestCacheIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public void testProfileDisableCache() throws Exception {
427427
)
428428
.get()
429429
);
430-
indexRandom(true, client.prepareIndex("index", "_doc").setSource("k", "hello"));
430+
indexRandom(true, client.prepareIndex("index").setSource("k", "hello"));
431431
ensureSearchable("index");
432432

433433
int expectedHits = 0;

0 commit comments

Comments
 (0)