diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml
index ab0a75a007aa4..a96b6aad53f7f 100644
--- a/buildSrc/src/main/resources/checkstyle_suppressions.xml
+++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml
@@ -2988,7 +2988,6 @@
-
@@ -3048,7 +3047,6 @@
-
diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java
index dc7021e81fcaf..7b351bba55ca2 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexModule.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java
@@ -21,7 +21,6 @@
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.client.Client;
-import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.TriFunction;
import org.elasticsearch.common.settings.Setting;
@@ -50,6 +49,7 @@
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.script.ScriptService;
+import org.elasticsearch.script.TemplateService;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.IOException;
@@ -320,20 +320,19 @@ public interface IndexSearcherWrapperFactory {
}
public IndexService newIndexService(
- NodeEnvironment environment,
- NamedXContentRegistry xContentRegistry,
- IndexService.ShardStoreDeleter shardStoreDeleter,
- CircuitBreakerService circuitBreakerService,
- BigArrays bigArrays,
- ThreadPool threadPool,
- ScriptService scriptService,
- ClusterService clusterService,
- Client client,
- IndicesQueryCache indicesQueryCache,
- MapperRegistry mapperRegistry,
- Consumer globalCheckpointSyncer,
- IndicesFieldDataCache indicesFieldDataCache)
- throws IOException {
+ NodeEnvironment environment,
+ NamedXContentRegistry xContentRegistry,
+ IndexService.ShardStoreDeleter shardStoreDeleter,
+ CircuitBreakerService circuitBreakerService,
+ BigArrays bigArrays,
+ ThreadPool threadPool,
+ ScriptService scriptService,
+ TemplateService templateService,
+ Client client,
+ IndicesQueryCache indicesQueryCache,
+ MapperRegistry mapperRegistry,
+ Consumer globalCheckpointSyncer,
+ IndicesFieldDataCache indicesFieldDataCache) throws IOException {
final IndexEventListener eventListener = freeze();
IndexSearcherWrapperFactory searcherWrapperFactory = indexSearcherWrapper.get() == null
? (shard) -> null : indexSearcherWrapper.get();
@@ -365,7 +364,7 @@ public IndexService newIndexService(
}
return new IndexService(indexSettings, environment, xContentRegistry, new SimilarityService(indexSettings, similarities),
shardStoreDeleter, analysisRegistry, engineFactory.get(), circuitBreakerService, bigArrays, threadPool, scriptService,
- clusterService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry,
+ templateService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry,
indicesFieldDataCache, globalCheckpointSyncer, searchOperationListeners, indexOperationListeners);
}
diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java
index ee35993c01e79..6baf4e28df9e5 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexService.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexService.java
@@ -28,7 +28,6 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.ShardRouting;
-import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
@@ -68,6 +67,7 @@
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.script.ScriptService;
+import org.elasticsearch.script.TemplateService;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.Closeable;
@@ -118,7 +118,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
private final BigArrays bigArrays;
private final AsyncGlobalCheckpointTask globalCheckpointTask;
private final ScriptService scriptService;
- private final ClusterService clusterService;
+ private final TemplateService templateService;
private final Client client;
public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
@@ -131,7 +131,7 @@ public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
BigArrays bigArrays,
ThreadPool threadPool,
ScriptService scriptService,
- ClusterService clusterService,
+ TemplateService templateService,
Client client,
QueryCache queryCache,
IndexStore indexStore,
@@ -158,7 +158,7 @@ public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
this.bigArrays = bigArrays;
this.threadPool = threadPool;
this.scriptService = scriptService;
- this.clusterService = clusterService;
+ this.templateService = templateService;
this.client = client;
this.eventListener = eventListener;
this.nodeEnv = nodeEnv;
@@ -473,7 +473,7 @@ public IndexSettings getIndexSettings() {
public QueryShardContext newQueryShardContext(int shardId, IndexReader indexReader, LongSupplier nowInMillis) {
return new QueryShardContext(
shardId, indexSettings, indexCache.bitsetFilterCache(), indexFieldData, mapperService(),
- similarityService(), scriptService, xContentRegistry,
+ similarityService(), scriptService, templateService, xContentRegistry,
client, indexReader,
nowInMillis);
}
@@ -499,6 +499,13 @@ public ScriptService getScriptService() {
return scriptService;
}
+ /**
+ * The {@link TemplateService} to use for this index.
+ */
+ public TemplateService getTemplateService() {
+ return templateService;
+ }
+
List getIndexOperationListeners() { // pkg private for testing
return indexingOperationListeners;
}
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 80726496a739c..c834b5b4ac272 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java
@@ -25,10 +25,10 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.MapperService;
-import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
+import org.elasticsearch.script.TemplateService;
import java.util.function.LongSupplier;
@@ -38,6 +38,7 @@
public class QueryRewriteContext {
protected final MapperService mapperService;
protected final ScriptService scriptService;
+ private final TemplateService templateService;
protected final IndexSettings indexSettings;
private final NamedXContentRegistry xContentRegistry;
protected final Client client;
@@ -45,10 +46,11 @@ public class QueryRewriteContext {
protected final LongSupplier nowInMillis;
public QueryRewriteContext(IndexSettings indexSettings, MapperService mapperService, ScriptService scriptService,
- NamedXContentRegistry xContentRegistry, Client client, IndexReader reader,
+ TemplateService templateService, NamedXContentRegistry xContentRegistry, Client client, IndexReader reader,
LongSupplier nowInMillis) {
this.mapperService = mapperService;
this.scriptService = scriptService;
+ this.templateService = templateService;
this.indexSettings = indexSettings;
this.xContentRegistry = xContentRegistry;
this.client = client;
@@ -104,7 +106,17 @@ public long nowInMillis() {
}
public BytesReference getTemplateBytes(Script template) {
- ExecutableScript executable = scriptService.executable(template, ScriptContext.Standard.SEARCH);
- return (BytesReference) executable.run();
+ return templateService
+ .template(template.getIdOrCode(), template.getType(),
+ ScriptContext.Standard.SEARCH, null)
+ .apply(template.getParams());
+ }
+
+ public ScriptService getScriptService() {
+ return scriptService;
+ }
+
+ public TemplateService getTemplateService() {
+ return templateService;
}
}
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 2b5e69947f373..0b08ccbd8ae2f 100644
--- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
+++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
@@ -56,6 +56,7 @@
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.SearchScript;
+import org.elasticsearch.script.TemplateService;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
@@ -100,9 +101,9 @@ public String[] getTypes() {
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
IndexFieldDataService indexFieldDataService, MapperService mapperService, SimilarityService similarityService,
- ScriptService scriptService, NamedXContentRegistry xContentRegistry,
+ ScriptService scriptService, TemplateService templateService, NamedXContentRegistry xContentRegistry,
Client client, IndexReader reader, LongSupplier nowInMillis) {
- super(indexSettings, mapperService, scriptService, xContentRegistry, client, reader, nowInMillis);
+ super(indexSettings, mapperService, scriptService, templateService, xContentRegistry, client, reader, nowInMillis);
this.shardId = shardId;
this.indexSettings = indexSettings;
this.similarityService = similarityService;
@@ -116,7 +117,7 @@ public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterC
public QueryShardContext(QueryShardContext source) {
this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService,
- source.similarityService, source.scriptService, source.getXContentRegistry(), source.client,
+ source.similarityService, source.scriptService, source.getTemplateService(), source.getXContentRegistry(), source.client,
source.reader, source.nowInMillis);
this.types = source.getTypes();
}
@@ -355,13 +356,14 @@ public final ExecutableScript getExecutableScript(Script script, ScriptContext c
}
/**
- * Returns a lazily created {@link ExecutableScript} that is compiled immediately but can be pulled later once all
- * parameters are available.
+ * Returns {@link Function} representing a script that is compiled immediately but can be pulled
+ * later once all parameters are available.
*/
- public final Function