org.elasticsearch.script.TemplateScript Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :distribution:archives:integ-test-zip
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.script;
import org.elasticsearch.core.TimeValue;
import java.util.Map;
/**
* A string template rendered as a script.
*/
public abstract class TemplateScript {
private final Map params;
public TemplateScript(Map params) {
this.params = params;
}
/** Return the parameters for this script. */
public Map getParams() {
return params;
}
public static final String[] PARAMETERS = {};
/** Run a template and return the resulting string, encoded in utf8 bytes. */
public abstract String execute();
public interface Factory {
TemplateScript newInstance(Map params);
}
public static final ScriptContext CONTEXT = new ScriptContext<>("template", Factory.class);
// Remove compilation rate limit for ingest. Ingest pipelines may use many mustache templates, triggering compilation
// rate limiting. MustacheScriptEngine explicitly checks for TemplateScript. Rather than complicating the implementation there by
// creating a new Script class (as would be customary), this context is used to avoid the default rate limit.
public static final ScriptContext INGEST_CONTEXT = new ScriptContext<>(
"ingest_template",
Factory.class,
200,
TimeValue.timeValueMillis(0),
false,
true
);
}