OpenSearch/docs/reference/migration/migrate_2_0/scripting.asciidoc

103 lines
2.1 KiB
Plaintext

=== Scripting changes
==== Scripting syntax
The syntax for scripts has been made consistent across all APIs. The accepted
format is as follows:
Inline/Dynamic scripts::
+
--
[source,js]
---------------
"script": {
"inline": "doc['foo'].value + val", <1>
"lang": "groovy", <2>
"params": { "val": 3 } <3>
}
---------------
<1> The inline script to execute.
<2> The optional language of the script.
<3> Any named parameters.
--
Indexed scripts::
+
--
[source,js]
---------------
"script": {
"id": "my_script_id", <1>
"lang": "groovy", <2>
"params": { "val": 3 } <3>
}
---------------
<1> The ID of the indexed script.
<2> The optional language of the script.
<3> Any named parameters.
--
File scripts::
+
--
[source,js]
---------------
"script": {
"file": "my_file", <1>
"lang": "groovy", <2>
"params": { "val": 3 } <3>
}
---------------
<1> The filename of the script, without the `.lang` suffix.
<2> The optional language of the script.
<3> Any named parameters.
--
For example, an update request might look like this:
[source,js]
---------------
POST my_index/my_type/1/_update
{
"script": {
"inline": "ctx._source.count += val",
"params": { "val": 3 }
},
"upsert": {
"count": 0
}
}
---------------
A short syntax exists for running inline scripts in the default scripting
language without any parameters:
[source,js]
----------------
GET _search
{
"script_fields": {
"concat_fields": {
"script": "doc['one'].value + ' ' + doc['two'].value"
}
}
}
----------------
==== Scripting settings
The `script.disable_dynamic` node setting has been replaced by fine-grained
script settings described in <<migration-script-settings>>.
==== Groovy scripts sandbox
The Groovy sandbox and related settings have been removed. Groovy is now a
non-sandboxed scripting language, without any option to turn the sandbox on.
==== Plugins making use of scripts
Plugins that make use of scripts must register their own script context
through `ScriptModule`. Script contexts can be used as part of fine-grained
settings to enable/disable scripts selectively.