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 c3d27b5d615..55ba778d012 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java
@@ -137,6 +137,10 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
this.executionMode.set(Boolean.TRUE);
}
+ /**
+ * This method fails if {@link #setExecutionMode()} is called before on this context.
+ * This is used to seal
+ */
protected void failIfExecutionMode() {
this.cachable = false;
if (executionMode.get() == Boolean.TRUE) {
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 3869ecfd2c1..d15c69e088e 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
@@ -335,11 +335,17 @@ public class QueryShardContext extends QueryRewriteContext {
return indexSettings.getIndex();
}
+ /**
+ * Compiles (or retrieves from cache) and executes the provided script
+ */
public SearchScript getSearchScript(Script script, ScriptContext context, Map params) {
failIfExecutionMode();
return scriptService.search(lookup(), script, context, params);
}
-
+ /**
+ * Returns a lazily created {@link SearchScript} that is compiled immediately but can be pulled later once all
+ * parameters are available.
+ */
public Function