Scripting: Simplify search method on script service (#24817)
This commit is a simple cleanup to remove an unnecessary extra method on ScriptService which was only used in 3 places. There is now only one search method.
This commit is contained in:
parent
2de748859f
commit
679ec99fad
|
@ -333,7 +333,8 @@ public class QueryShardContext extends QueryRewriteContext {
|
|||
*/
|
||||
public final SearchScript getSearchScript(Script script, ScriptContext context) {
|
||||
failIfFrozen();
|
||||
return scriptService.search(lookup(), script, context);
|
||||
CompiledScript compile = scriptService.compile(script, context);
|
||||
return scriptService.search(lookup(), compile, script.getParams());
|
||||
}
|
||||
/**
|
||||
* Returns a lazily created {@link SearchScript} that is compiled immediately but can be pulled later once all
|
||||
|
|
|
@ -508,14 +508,6 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
|
|||
return getEngine(compiledScript.lang()).executable(compiledScript, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles (or retrieves from cache) and executes the provided search script
|
||||
*/
|
||||
public SearchScript search(SearchLookup lookup, Script script, ScriptContext scriptContext) {
|
||||
CompiledScript compiledScript = compile(script, scriptContext);
|
||||
return search(lookup, compiledScript, script.getParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds provided parameters to a compiled script returning a
|
||||
* {@link SearchScript} ready for execution
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.elasticsearch.index.shard.IndexShard;
|
|||
import org.elasticsearch.index.shard.SearchOperationListener;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
|
@ -685,7 +686,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|||
}
|
||||
if (source.scriptFields() != null) {
|
||||
for (org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField field : source.scriptFields()) {
|
||||
SearchScript searchScript = scriptService.search(context.lookup(), field.script(), ScriptContext.Standard.SEARCH);
|
||||
CompiledScript compile = scriptService.compile(field.script(), ScriptContext.Standard.SEARCH);
|
||||
SearchScript searchScript = scriptService.search(context.lookup(), compile, field.script().getParams());
|
||||
context.scriptFields().add(new ScriptField(field.fieldName(), searchScript, field.ignoreFailure()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,7 +244,9 @@ public class ScriptServiceTests extends ESTestCase {
|
|||
|
||||
public void testSearchCountedInCompilationStats() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
scriptService.search(null, new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
Script script = new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap());
|
||||
CompiledScript compile = scriptService.compile(script, randomFrom(scriptContexts));
|
||||
scriptService.search(null, compile, script.getParams());
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue