use a private rewrite context to prevent exposing isCachable
This commit is contained in:
parent
7ba22bb75b
commit
e556c289b9
|
@ -119,18 +119,13 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
|
|||
return new QueryParseContext(defaultScriptLanguage, indicesQueriesRegistry, parser, indexSettings.getParseFieldMatcher());
|
||||
}
|
||||
|
||||
protected final void markAsNotCachable() {
|
||||
this.cachable = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> iff the result of the processed search request is cachable. Otherwise <code>false</code>
|
||||
*/
|
||||
public boolean isCachable() {
|
||||
return cachable;
|
||||
}
|
||||
|
||||
public void setCachable(boolean cachabe) {
|
||||
this.cachable = cachabe;
|
||||
}
|
||||
|
||||
public BytesReference getTemplateBytes(Script template) {
|
||||
failIfExecutionMode();
|
||||
ExecutableScript executable = scriptService.executable(template,
|
||||
|
@ -143,7 +138,7 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
|
|||
}
|
||||
|
||||
protected void failIfExecutionMode() {
|
||||
markAsNotCachable();
|
||||
this.cachable = false;
|
||||
if (executionMode.get() == Boolean.TRUE) {
|
||||
throw new IllegalArgumentException("features that prevent cachability are disabled on this context");
|
||||
} else {
|
||||
|
|
|
@ -521,13 +521,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|||
DefaultSearchContext context = createSearchContext(request, defaultSearchTimeout, searcher);
|
||||
SearchContext.setCurrent(context);
|
||||
try {
|
||||
request.rewrite(context.getQueryShardContext());
|
||||
// reset that we have used nowInMillis from the context since it may
|
||||
// have been rewritten so its no longer in the query and the request can
|
||||
// be cached. If it is still present in the request (e.g. in a range
|
||||
// aggregation) it will still be caught when the aggregation is
|
||||
// evaluated.
|
||||
context.resetCanCache();
|
||||
request.rewrite(new QueryShardContext(context.getQueryShardContext()));
|
||||
if (request.scroll() != null) {
|
||||
context.scrollContext(new ScrollContext());
|
||||
context.scrollContext().scroll = request.scroll();
|
||||
|
|
|
@ -163,10 +163,6 @@ public abstract class SearchContext extends AbstractRefCounted implements Releas
|
|||
return getQueryShardContext().isCachable();
|
||||
}
|
||||
|
||||
public final void resetCanCache() {
|
||||
getQueryShardContext().setCachable(true);
|
||||
}
|
||||
|
||||
public abstract ScrollContext scrollContext();
|
||||
|
||||
public abstract SearchContext scrollContext(ScrollContext scroll);
|
||||
|
|
|
@ -585,7 +585,11 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
QB firstQuery = createTestQueryBuilder();
|
||||
QB controlQuery = copyQuery(firstQuery);
|
||||
setSearchContext(randomTypes, context); // only set search context for toQuery to be more realistic
|
||||
Query firstLuceneQuery = rewriteQuery(firstQuery, context).toQuery(context);
|
||||
/* we use a private rewrite context here since we want the most realistic way of asserting that we are cachabel or not.
|
||||
* We do it this way in SearchService where
|
||||
* we first rewrite the query with a private context, then reset the context and then build the actual lucene query*/
|
||||
QueryBuilder rewritten = rewriteQuery(firstQuery, new QueryShardContext(context));
|
||||
Query firstLuceneQuery = rewritten.toQuery(context);
|
||||
if (isCachable(firstQuery)) {
|
||||
assert context.isCachable() : firstQuery.toString();
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue