summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java')
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java30
1 files changed, 16 insertions, 14 deletions
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 31b2a71846..c4093be5dd 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
@@ -32,7 +32,6 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.index.Index;
@@ -50,7 +49,6 @@ import org.elasticsearch.index.mapper.ObjectMapper;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.query.support.NestedScope;
import org.elasticsearch.index.similarity.SimilarityService;
-import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
@@ -331,39 +329,43 @@ public class QueryShardContext extends QueryRewriteContext {
* Compiles (or retrieves from cache) and binds the parameters to the
* provided script
*/
- public final SearchScript getSearchScript(Script script, ScriptContext context) {
+ public final SearchScript getSearchScript(Script script, ScriptContext<SearchScript, SearchScript.Compiled> context) {
failIfFrozen();
- CompiledScript compile = scriptService.compile(script, context);
- return scriptService.search(lookup(), compile, script.getParams());
+ SearchScript.Compiled compiled = scriptService.compile(script, context);
+ return compiled.newInstance(script.getParams(), lookup());
}
/**
* Returns a lazily created {@link SearchScript} that is compiled immediately but can be pulled later once all
* parameters are available.
*/
- public final Function<Map<String, Object>, SearchScript> getLazySearchScript(Script script, ScriptContext context) {
+ public final Function<Map<String, Object>, SearchScript> getLazySearchScript(
+ Script script, ScriptContext<SearchScript, SearchScript.Compiled> context) {
+ // TODO: this "lazy" binding can be removed once scripted metric aggs have their own contexts, which take _agg/_aggs as a parameter
failIfFrozen();
- CompiledScript compile = scriptService.compile(script, context);
- return (p) -> scriptService.search(lookup(), compile, p);
+ SearchScript.Compiled compiled = scriptService.compile(script, context);
+ return (p) -> compiled.newInstance(p, lookup());
}
/**
* Compiles (or retrieves from cache) and binds the parameters to the
* provided script
*/
- public final ExecutableScript getExecutableScript(Script script, ScriptContext context) {
+ public final ExecutableScript getExecutableScript(Script script, ScriptContext<ExecutableScript, ExecutableScript.Compiled> context) {
failIfFrozen();
- CompiledScript compiledScript = scriptService.compile(script, context);
- return scriptService.executable(compiledScript, script.getParams());
+ ExecutableScript.Compiled compiled = scriptService.compile(script, context);
+ return compiled.newInstance(script.getParams());
}
/**
* Returns a lazily created {@link ExecutableScript} that is compiled immediately but can be pulled later once all
* parameters are available.
*/
- public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(Script script, ScriptContext context) {
+ public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(
+ Script script, ScriptContext<ExecutableScript, ExecutableScript.Compiled> context) {
+ // TODO: this "lazy" binding can be removed once scripted metric aggs have their own contexts, which take _agg/_aggs as a parameter
failIfFrozen();
- CompiledScript executable = scriptService.compile(script, context);
- return (p) -> scriptService.executable(executable, p);
+ ExecutableScript.Compiled compiled = scriptService.compile(script, context);
+ return compiled::newInstance;
}
/**