summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch')
-rw-r--r--core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java2
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java2
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java2
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java2
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java2
-rw-r--r--core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java2
-rw-r--r--core/src/main/java/org/elasticsearch/node/Node.java2
-rw-r--r--core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java10
-rw-r--r--core/src/main/java/org/elasticsearch/script/ScriptContext.java100
-rw-r--r--core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java93
-rw-r--r--core/src/main/java/org/elasticsearch/script/ScriptEngine.java9
-rw-r--r--core/src/main/java/org/elasticsearch/script/ScriptModule.java63
-rw-r--r--core/src/main/java/org/elasticsearch/script/ScriptService.java29
-rw-r--r--core/src/main/java/org/elasticsearch/search/SearchService.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java4
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetric.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java6
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java2
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java2
23 files changed, 90 insertions, 254 deletions
diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java b/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java
index 6ea50df6b5..c88b604e8c 100644
--- a/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java
+++ b/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java
@@ -301,7 +301,7 @@ public class UpdateHelper extends AbstractComponent {
private Map<String, Object> executeScript(Script script, Map<String, Object> ctx) {
try {
if (scriptService != null) {
- CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.UPDATE);
+ CompiledScript compiledScript = scriptService.compile(script, ScriptContext.UPDATE);
ExecutableScript executableScript = scriptService.executable(compiledScript, script.getParams());
executableScript.setNextVar(ContextFields.CTX, ctx);
executableScript.run();
diff --git a/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java b/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java
index 768f7e7fd0..d21d3d6670 100644
--- a/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java
+++ b/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java
@@ -620,7 +620,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
if (scriptFields != null) {
for (ScriptField field : scriptFields) {
SearchScript searchScript = innerHitsContext.getQueryShardContext().getSearchScript(field.script(),
- ScriptContext.Standard.SEARCH);
+ ScriptContext.SEARCH);
innerHitsContext.scriptFields().add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
field.fieldName(), searchScript, field.ignoreFailure()));
}
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 003187f1bb..37473710e2 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java
@@ -106,7 +106,7 @@ public class QueryRewriteContext {
}
public String getTemplateBytes(Script template) {
- CompiledTemplate compiledTemplate = scriptService.compileTemplate(template, ScriptContext.Standard.SEARCH);
+ CompiledTemplate compiledTemplate = scriptService.compileTemplate(template, ScriptContext.SEARCH);
return compiledTemplate.run(template.getParams());
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java
index 4ad2e7824e..140fc04c95 100644
--- a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java
+++ b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java
@@ -131,7 +131,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
- return new ScriptQuery(script, context.getSearchScript(script, ScriptContext.Standard.SEARCH));
+ return new ScriptQuery(script, context.getSearchScript(script, ScriptContext.SEARCH));
}
static class ScriptQuery extends Query {
diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java
index 4d61504a61..3195380d21 100644
--- a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java
+++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java
@@ -94,7 +94,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder<ScriptScore
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
try {
- SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
+ SearchScript searchScript = context.getSearchScript(script, ScriptContext.SEARCH);
return new ScriptScoreFunction(script, searchScript);
} catch (Exception e) {
throw new QueryShardException(context, "script_score: the script could not be loaded", e);
diff --git a/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java b/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java
index a54b5754a1..34a85ab9ab 100644
--- a/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java
+++ b/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java
@@ -44,7 +44,7 @@ public class InternalTemplateService implements TemplateService {
int mustacheEnd = template.indexOf("}}");
if (mustacheStart != -1 && mustacheEnd != -1 && mustacheStart < mustacheEnd) {
Script script = new Script(ScriptType.INLINE, "mustache", template, Collections.emptyMap());
- CompiledTemplate compiledTemplate = scriptService.compileTemplate(script, ScriptContext.Standard.INGEST);
+ CompiledTemplate compiledTemplate = scriptService.compileTemplate(script, ScriptContext.INGEST);
return new Template() {
@Override
public String execute(Map<String, Object> model) {
diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java
index dbf3d21181..dd50b0526e 100644
--- a/core/src/main/java/org/elasticsearch/node/Node.java
+++ b/core/src/main/java/org/elasticsearch/node/Node.java
@@ -325,7 +325,7 @@ public class Node implements Closeable {
}
client = new NodeClient(settings, threadPool);
final ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, threadPool);
- final ScriptModule scriptModule = ScriptModule.create(settings, pluginsService.filterPlugins(ScriptPlugin.class));
+ final ScriptModule scriptModule = new ScriptModule(settings, pluginsService.filterPlugins(ScriptPlugin.class));
AnalysisModule analysisModule = new AnalysisModule(this.environment, pluginsService.filterPlugins(AnalysisPlugin.class));
// this is as early as we can validate settings at this point. we already pass them to ScriptModule as well as ThreadPool
// so we might be late here already
diff --git a/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java b/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java
index 7ea767c182..125b58a498 100644
--- a/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java
+++ b/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java
@@ -18,6 +18,10 @@
*/
package org.elasticsearch.plugins;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptEngine;
@@ -35,9 +39,9 @@ public interface ScriptPlugin {
}
/**
- * Returns a {@link ScriptContext.Plugin} instance or <code>null</code> if this plugin doesn't add a new script context plugin
+ * Return script contexts this plugin wants to allow using.
*/
- default ScriptContext.Plugin getCustomScriptContexts() {
- return null;
+ default List<ScriptContext> getContexts() {
+ return Collections.emptyList();
}
}
diff --git a/core/src/main/java/org/elasticsearch/script/ScriptContext.java b/core/src/main/java/org/elasticsearch/script/ScriptContext.java
index cc2408786e..cd3bff3379 100644
--- a/core/src/main/java/org/elasticsearch/script/ScriptContext.java
+++ b/core/src/main/java/org/elasticsearch/script/ScriptContext.java
@@ -19,87 +19,35 @@
package org.elasticsearch.script;
-import org.elasticsearch.common.Strings;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
- * Context of an operation that uses scripts as part of its execution.
+ * A holder for information about a context in which a script is compiled and run.
*/
-public interface ScriptContext {
-
- /**
- * @return the name of the operation
- */
- String getKey();
-
- /**
- * Standard operations that make use of scripts as part of their execution.
- * Note that the suggest api is considered part of search for simplicity, as well as the percolate api.
- */
- enum Standard implements ScriptContext {
-
- AGGS("aggs"), SEARCH("search"), UPDATE("update"), INGEST("ingest");
-
- private final String key;
-
- Standard(String key) {
- this.key = key;
- }
-
- @Override
- public String getKey() {
- return key;
- }
-
- @Override
- public String toString() {
- return getKey();
- }
+public final class ScriptContext {
+
+ public static final ScriptContext AGGS = new ScriptContext("aggs");
+ public static final ScriptContext SEARCH = new ScriptContext("search");
+ public static final ScriptContext UPDATE = new ScriptContext("update");
+ public static final ScriptContext INGEST = new ScriptContext("ingest");
+
+ public static final Map<String, ScriptContext> BUILTINS;
+ static {
+ Map<String, ScriptContext> builtins = new HashMap<>();
+ builtins.put(AGGS.name, AGGS);
+ builtins.put(SEARCH.name, SEARCH);
+ builtins.put(UPDATE.name, UPDATE);
+ builtins.put(INGEST.name, INGEST);
+ BUILTINS = Collections.unmodifiableMap(builtins);
}
- /**
- * Custom operation exposed via plugin, which makes use of scripts as part of its execution
- */
- final class Plugin implements ScriptContext {
-
- private final String pluginName;
- private final String operation;
- private final String key;
-
- /**
- * Creates a new custom scripts based operation exposed via plugin.
- * The name of the plugin combined with the operation name can be used to enable/disable scripts via fine-grained settings.
- *
- * @param pluginName the name of the plugin
- * @param operation the name of the operation
- */
- public Plugin(String pluginName, String operation) {
- if (Strings.hasLength(pluginName) == false) {
- throw new IllegalArgumentException("plugin name cannot be empty when registering a custom script context");
- }
- if (Strings.hasLength(operation) == false) {
- throw new IllegalArgumentException("operation name cannot be empty when registering a custom script context");
- }
- this.pluginName = pluginName;
- this.operation = operation;
- this.key = pluginName + "_" + operation;
- }
-
- public String getPluginName() {
- return pluginName;
- }
-
- public String getOperation() {
- return operation;
- }
-
- @Override
- public String getKey() {
- return key;
- }
+ /** A unique identifier for this context. */
+ public final String name;
- @Override
- public String toString() {
- return getKey();
- }
+ // pkg private ctor, only created by script module
+ public ScriptContext(String name) {
+ this.name = name;
}
}
diff --git a/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java b/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java
deleted file mode 100644
index 765be1d437..0000000000
--- a/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to Elasticsearch under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.elasticsearch.script;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static java.util.Collections.unmodifiableMap;
-import static java.util.Collections.unmodifiableSet;
-
-/**
- * Registry for operations that use scripts as part of their execution. Can be standard operations of custom defined ones (via plugin).
- * Allows plugins to register custom operations that they use scripts for,
- * via {@link org.elasticsearch.plugins.ScriptPlugin}
- * Scripts can be enabled/disabled via fine-grained settings for each single registered operation.
- */
-public final class ScriptContextRegistry {
- static final Set<String> RESERVED_SCRIPT_CONTEXTS = reservedScriptContexts();
-
- private final Map<String, ScriptContext> scriptContexts;
-
- public ScriptContextRegistry(Collection<ScriptContext.Plugin> customScriptContexts) {
- Map<String, ScriptContext> scriptContexts = new HashMap<>();
- for (ScriptContext.Standard scriptContext : ScriptContext.Standard.values()) {
- scriptContexts.put(scriptContext.getKey(), scriptContext);
- }
- for (ScriptContext.Plugin customScriptContext : customScriptContexts) {
- validateScriptContext(customScriptContext);
- ScriptContext previousContext = scriptContexts.put(customScriptContext.getKey(), customScriptContext);
- if (previousContext != null) {
- throw new IllegalArgumentException("script context [" + customScriptContext.getKey() + "] cannot be registered twice");
- }
- }
- this.scriptContexts = unmodifiableMap(scriptContexts);
- }
-
- /**
- * @return a list that contains all the supported {@link ScriptContext}s, both standard ones and registered via plugins
- */
- Collection<ScriptContext> scriptContexts() {
- return scriptContexts.values();
- }
-
- /**
- * @return <tt>true</tt> if the provided {@link ScriptContext} is supported, <tt>false</tt> otherwise
- */
- boolean isSupportedContext(String scriptContext) {
- return scriptContexts.containsKey(scriptContext);
- }
-
- //script contexts can be used in fine-grained settings, we need to be careful with what we allow here
- private void validateScriptContext(ScriptContext.Plugin scriptContext) {
- if (RESERVED_SCRIPT_CONTEXTS.contains(scriptContext.getPluginName())) {
- throw new IllegalArgumentException("[" + scriptContext.getPluginName() + "] is a reserved name, it cannot be registered as a custom script context");
- }
- if (RESERVED_SCRIPT_CONTEXTS.contains(scriptContext.getOperation())) {
- throw new IllegalArgumentException("[" + scriptContext.getOperation() + "] is a reserved name, it cannot be registered as a custom script context");
- }
- }
-
- private static Set<String> reservedScriptContexts() {
- Set<String> reserved = new HashSet<>(ScriptType.values().length + ScriptContext.Standard.values().length);
- for (ScriptType scriptType : ScriptType.values()) {
- reserved.add(scriptType.toString());
- }
- for (ScriptContext.Standard scriptContext : ScriptContext.Standard.values()) {
- reserved.add(scriptContext.getKey());
- }
- reserved.add("script");
- reserved.add("engine");
- return unmodifiableSet(reserved);
- }
-}
diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngine.java b/core/src/main/java/org/elasticsearch/script/ScriptEngine.java
index caec832008..9572e891b3 100644
--- a/core/src/main/java/org/elasticsearch/script/ScriptEngine.java
+++ b/core/src/main/java/org/elasticsearch/script/ScriptEngine.java
@@ -37,13 +37,12 @@ public interface ScriptEngine extends Closeable {
/**
* Compiles a script.
- * @param scriptName name of the script. {@code null} if it is anonymous (inline).
- * For a file script, its the file name (with extension).
- * For a stored script, its the identifier.
- * @param scriptSource actual source of the script
+ * @param name the name of the script. {@code null} if it is anonymous (inline). For a stored script, its the identifier.
+ * @param code actual source of the script
* @param params compile-time parameters (such as flags to the compiler)
+ * @return an opaque compiled script which may be cached and later passed to
*/
- Object compile(String scriptName, String scriptSource, Map<String, String> params);
+ Object compile(String name, String code, Map<String, String> params);
ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> vars);
diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModule.java b/core/src/main/java/org/elasticsearch/script/ScriptModule.java
index 7668b38c4c..b29a199c3a 100644
--- a/core/src/main/java/org/elasticsearch/script/ScriptModule.java
+++ b/core/src/main/java/org/elasticsearch/script/ScriptModule.java
@@ -19,17 +19,14 @@
package org.elasticsearch.script;
-import org.elasticsearch.common.settings.ClusterSettings;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.plugins.ScriptPlugin;
-
-import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
+
+import org.elasticsearch.common.settings.ClusterSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.plugins.ScriptPlugin;
/**
* Manages building {@link ScriptService}.
@@ -37,42 +34,26 @@ import java.util.stream.Collectors;
public class ScriptModule {
private final ScriptService scriptService;
- /**
- * Build from {@linkplain ScriptPlugin}s. Convenient for normal use but not great for tests. See
- * {@link ScriptModule#ScriptModule(Settings, List, List)} for easier use in tests.
- */
- public static ScriptModule create(Settings settings, List<ScriptPlugin> scriptPlugins) {
- List<ScriptEngine> scriptEngines = scriptPlugins.stream().map(x -> x.getScriptEngine(settings))
- .filter(Objects::nonNull).collect(Collectors.toList());
- List<ScriptContext.Plugin> plugins = scriptPlugins.stream().map(x -> x.getCustomScriptContexts()).filter(Objects::nonNull)
- .collect(Collectors.toList());
- return new ScriptModule(settings, scriptEngines, plugins);
- }
-
- /**
- * Build {@linkplain ScriptEngine} and {@linkplain ScriptContext.Plugin}.
- */
- public ScriptModule(Settings settings, List<ScriptEngine> scriptEngines,
- List<ScriptContext.Plugin> customScriptContexts) {
- ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts);
- Map<String, ScriptEngine> enginesByName = getEnginesByName(scriptEngines);
- try {
- scriptService = new ScriptService(settings, enginesByName, scriptContextRegistry);
- } catch (IOException e) {
- throw new RuntimeException("Couldn't setup ScriptService", e);
- }
- }
-
- private Map<String, ScriptEngine> getEnginesByName(List<ScriptEngine> engines) {
- Map<String, ScriptEngine> enginesByName = new HashMap<>();
- for (ScriptEngine engine : engines) {
- ScriptEngine existing = enginesByName.put(engine.getType(), engine);
- if (existing != null) {
- throw new IllegalArgumentException("scripting language [" + engine.getType() + "] defined for engine [" +
- existing.getClass().getName() + "] and [" + engine.getClass().getName());
+ public ScriptModule(Settings settings, List<ScriptPlugin> scriptPlugins) {
+ Map<String, ScriptEngine> engines = new HashMap<>();
+ Map<String, ScriptContext> contexts = new HashMap<>(ScriptContext.BUILTINS);
+ for (ScriptPlugin plugin : scriptPlugins) {
+ for (ScriptContext context : plugin.getContexts()) {
+ ScriptContext oldContext = contexts.put(context.name, context);
+ if (oldContext != null) {
+ throw new IllegalArgumentException("Context name [" + context.name + "] defined twice");
+ }
+ }
+ ScriptEngine engine = plugin.getScriptEngine(settings);
+ if (engine != null) {
+ ScriptEngine existing = engines.put(engine.getType(), engine);
+ if (existing != null) {
+ throw new IllegalArgumentException("scripting language [" + engine.getType() + "] defined for engine [" +
+ existing.getClass().getName() + "] and [" + engine.getClass().getName());
+ }
}
}
- return Collections.unmodifiableMap(enginesByName);
+ scriptService = new ScriptService(settings, Collections.unmodifiableMap(engines), Collections.unmodifiableMap(contexts));
}
/**
diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java
index b681d07e98..656149be34 100644
--- a/core/src/main/java/org/elasticsearch/script/ScriptService.java
+++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java
@@ -82,11 +82,10 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
private final Set<String> contextsAllowed;
private final Map<String, ScriptEngine> engines;
+ private final Map<String, ScriptContext> contexts;
private final Cache<CacheKey, CompiledScript> cache;
- private final ScriptContextRegistry scriptContextRegistry;
-
private final ScriptMetrics scriptMetrics = new ScriptMetrics();
private ClusterState clusterState;
@@ -96,12 +95,12 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
private double scriptsPerMinCounter;
private double compilesAllowedPerNano;
- public ScriptService(Settings settings, Map<String, ScriptEngine> engines, ScriptContextRegistry scriptContextRegistry) throws IOException {
+ public ScriptService(Settings settings, Map<String, ScriptEngine> engines, Map<String, ScriptContext> contexts) {
super(settings);
Objects.requireNonNull(settings);
this.engines = Objects.requireNonNull(engines);
- Objects.requireNonNull(scriptContextRegistry);
+ this.contexts = Objects.requireNonNull(contexts);
if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
throw new IllegalArgumentException(DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings. \n" +
@@ -166,7 +165,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
}
}
- if (scriptContextRegistry.isSupportedContext(settingContext)) {
+ if (contexts.containsKey(settingContext)) {
this.contextsAllowed.add(settingContext);
} else {
throw new IllegalArgumentException(
@@ -175,8 +174,6 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
}
}
- this.scriptContextRegistry = scriptContextRegistry;
-
int cacheMaxSize = SCRIPT_CACHE_SIZE_SETTING.get(settings);
CacheBuilder<CacheKey, CompiledScript> cacheBuilder = CacheBuilder.builder();
@@ -223,9 +220,9 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
/**
* Checks if a script can be executed and compiles it if needed, or returns the previously compiled and cached script.
*/
- public CompiledScript compile(Script script, ScriptContext scriptContext) {
+ public CompiledScript compile(Script script, ScriptContext context) {
Objects.requireNonNull(script);
- Objects.requireNonNull(scriptContext);
+ Objects.requireNonNull(context);
ScriptType type = script.getType();
String lang = script.getLang();
@@ -266,10 +263,10 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
// TODO: fix this through some API or something, that's wrong
// special exception to prevent expressions from compiling as update or mapping scripts
boolean expression = "expression".equals(script.getLang());
- boolean notSupported = scriptContext.getKey().equals(ScriptContext.Standard.UPDATE.getKey());
+ boolean notSupported = context.name.equals(ScriptContext.UPDATE.name);
if (expression && notSupported) {
throw new UnsupportedOperationException("scripts of type [" + script.getType() + "]," +
- " operation [" + scriptContext.getKey() + "] and lang [" + lang + "] are not supported");
+ " operation [" + context.name + "] and lang [" + lang + "] are not supported");
}
ScriptEngine scriptEngine = getEngine(lang);
@@ -278,12 +275,12 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
throw new IllegalArgumentException("cannot execute [" + type + "] scripts");
}
- if (scriptContextRegistry.isSupportedContext(scriptContext.getKey()) == false) {
- throw new IllegalArgumentException("script context [" + scriptContext.getKey() + "] not supported");
+ if (contexts.containsKey(context.name) == false) {
+ throw new IllegalArgumentException("script context [" + context.name + "] not supported");
}
- if (isContextEnabled(scriptContext) == false) {
- throw new IllegalArgumentException("cannot execute scripts using [" + scriptContext.getKey() + "] context");
+ if (isContextEnabled(context) == false) {
+ throw new IllegalArgumentException("cannot execute scripts using [" + context.name + "] context");
}
if (logger.isTraceEnabled()) {
@@ -380,7 +377,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
}
public boolean isContextEnabled(ScriptContext scriptContext) {
- return contextsAllowed == null || contextsAllowed.contains(scriptContext.getKey());
+ return contextsAllowed == null || contextsAllowed.contains(scriptContext.name);
}
public boolean isAnyContextEnabled() {
diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java
index b6ac31c1d0..ac7c33094e 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchService.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchService.java
@@ -686,7 +686,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
}
if (source.scriptFields() != null) {
for (org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField field : source.scriptFields()) {
- CompiledScript compile = scriptService.compile(field.script(), ScriptContext.Standard.SEARCH);
+ CompiledScript compile = scriptService.compile(field.script(), ScriptContext.SEARCH);
SearchScript searchScript = scriptService.search(context.lookup(), compile, field.script().getParams());
context.scriptFields().add(new ScriptField(field.fieldName(), searchScript, field.ignoreFailure()));
}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java
index 7618839d49..b3df54247b 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java
@@ -93,13 +93,13 @@ public class ScriptHeuristic extends SignificanceHeuristic {
@Override
public SignificanceHeuristic rewrite(InternalAggregation.ReduceContext context) {
- CompiledScript compiledScript = context.scriptService().compile(script, ScriptContext.Standard.AGGS);
+ CompiledScript compiledScript = context.scriptService().compile(script, ScriptContext.AGGS);
return new ExecutableScriptHeuristic(script, context.scriptService().executable(compiledScript, script.getParams()));
}
@Override
public SignificanceHeuristic rewrite(SearchContext context) {
- return new ExecutableScriptHeuristic(script, context.getQueryShardContext().getExecutableScript(script, ScriptContext.Standard.AGGS));
+ return new ExecutableScriptHeuristic(script, context.getQueryShardContext().getExecutableScript(script, ScriptContext.AGGS));
}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetric.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetric.java
index ea0fa4ce19..2bedd16ebf 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetric.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetric.java
@@ -97,7 +97,7 @@ public class InternalScriptedMetric extends InternalAggregation implements Scrip
vars.putAll(firstAggregation.reduceScript.getParams());
}
CompiledScript compiledScript = reduceContext.scriptService().compile(
- firstAggregation.reduceScript, ScriptContext.Standard.AGGS);
+ firstAggregation.reduceScript, ScriptContext.AGGS);
ExecutableScript script = reduceContext.scriptService().executable(compiledScript, vars);
aggregation = Collections.singletonList(script.run());
} else if (reduceContext.isFinalReduce()) {
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java
index 2d6398ee31..6d8c297eeb 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java
@@ -186,15 +186,15 @@ public class ScriptedMetricAggregationBuilder extends AbstractAggregationBuilder
QueryShardContext queryShardContext = context.getQueryShardContext();
Function<Map<String, Object>, ExecutableScript> executableInitScript;
if (initScript != null) {
- executableInitScript = queryShardContext.getLazyExecutableScript(initScript, ScriptContext.Standard.AGGS);
+ executableInitScript = queryShardContext.getLazyExecutableScript(initScript, ScriptContext.AGGS);
} else {
executableInitScript = (p) -> null;
}
Function<Map<String, Object>, SearchScript> searchMapScript = queryShardContext.getLazySearchScript(mapScript,
- ScriptContext.Standard.AGGS);
+ ScriptContext.AGGS);
Function<Map<String, Object>, ExecutableScript> executableCombineScript;
if (combineScript != null) {
- executableCombineScript = queryShardContext.getLazyExecutableScript(combineScript, ScriptContext.Standard.AGGS);
+ executableCombineScript = queryShardContext.getLazyExecutableScript(combineScript, ScriptContext.AGGS);
} else {
executableCombineScript = (p) -> null;
}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java
index 68a16b4d3c..0ff94e9aa9 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java
@@ -534,7 +534,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
if (scriptFields != null) {
for (ScriptField field : scriptFields) {
SearchScript searchScript = context.getQueryShardContext().getSearchScript(field.script(),
- ScriptContext.Standard.SEARCH);
+ ScriptContext.SEARCH);
fields.add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
field.fieldName(), searchScript, field.ignoreFailure()));
}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java
index 87df926eba..46f4fbb237 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java
@@ -91,7 +91,7 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
(InternalMultiBucketAggregation<InternalMultiBucketAggregation, InternalMultiBucketAggregation.InternalBucket>) aggregation;
List<? extends InternalMultiBucketAggregation.InternalBucket> buckets = originalAgg.getBuckets();
- CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.Standard.AGGS);
+ CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.AGGS);
List<InternalMultiBucketAggregation.InternalBucket> newBuckets = new ArrayList<>();
for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
Map<String, Object> vars = new HashMap<>();
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java
index 62eed8d4e0..f5bc5cc4ad 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java
@@ -84,7 +84,7 @@ public class BucketSelectorPipelineAggregator extends PipelineAggregator {
(InternalMultiBucketAggregation<InternalMultiBucketAggregation, InternalMultiBucketAggregation.InternalBucket>) aggregation;
List<? extends InternalMultiBucketAggregation.InternalBucket> buckets = originalAgg.getBuckets();
- CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.Standard.AGGS);
+ CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.AGGS);
List<InternalMultiBucketAggregation.InternalBucket> newBuckets = new ArrayList<>();
for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
Map<String, Object> vars = new HashMap<>();
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java
index e5fac62840..ea2afdb7e8 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java
@@ -120,7 +120,7 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
if (script == null) {
return null;
} else {
- return context.getSearchScript(script, ScriptContext.Standard.AGGS);
+ return context.getSearchScript(script, ScriptContext.AGGS);
}
}
diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
index b136dd7798..c775cc8149 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
@@ -242,7 +242,7 @@ public class ScriptSortBuilder extends SortBuilder<ScriptSortBuilder> {
@Override
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
- final SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
+ final SearchScript searchScript = context.getSearchScript(script, ScriptContext.SEARCH);
MultiValueMode valueMode = null;
if (sortMode != null) {
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java
index 49c5f5a9fd..f5a6eca35b 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java
@@ -631,7 +631,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSuggestionB
if (this.collateQuery != null) {
Function<Map<String, Object>, ExecutableScript> compiledScript = context.getLazyExecutableScript(this.collateQuery,
- ScriptContext.Standard.SEARCH);
+ ScriptContext.SEARCH);
suggestionContext.setCollateQueryScript(compiledScript);
if (this.collateParams != null) {
suggestionContext.setCollateScriptParams(this.collateParams);