OpenSearch/docs/java-api/admin/cluster/stored-scripts.asciidoc

30 lines
1.1 KiB
Plaintext

[[stored-scripts]]
==== Stored Scripts API
The stored script API allows one to interact with scripts and templates
stored in Elasticsearch. It can be used to create, update, get,
and delete stored scripts and templates.
[source,java]
--------------------------------------------------
PutStoredScriptResponse response = client.admin().cluster().preparePutStoredScript()
.setId("script1")
.setContent(new BytesArray("{\"script\": {\"lang\": \"painless\", \"source\": \"_score * doc['my_numeric_field'].value\"} }"), XContentType.JSON)
.get();
GetStoredScriptResponse response = client().admin().cluster().prepareGetStoredScript()
.setId("script1")
.get();
DeleteStoredScriptResponse response = client().admin().cluster().prepareDeleteStoredScript()
.setId("script1")
.get();
--------------------------------------------------
To store templates simply use "mustache" for the scriptLang.
===== Script Language
The put stored script API allows one to set the language of the stored script.
If one is not provided the default scripting language will be used.