mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Change Namespace for Stored Script to Only Use Id (#22206)
Currently, stored scripts use a namespace of (lang, id) to be put, get, deleted, and executed. This is not necessary since the lang is stored with the stored script. A user should only have to specify an id to use a stored script. This change makes that possible while keeping backwards compatibility with the previous namespace of (lang, id). Anywhere the previous namespace is used will log deprecation warnings. The new behavior is the following: When a user specifies a stored script, that script will be stored under both the new namespace and old namespace. Take for example script 'A' with lang 'L0' and data 'D0'. If we add script 'A' to the empty set, the scripts map will be ["A" -- D0, "A#L0" -- D0]. If a script 'A' with lang 'L1' and data 'D1' is then added, the scripts map will be ["A" -- D1, "A#L1" -- D1, "A#L0" -- D0]. When a user deletes a stored script, that script will be deleted from both the new namespace (if it exists) and the old namespace. Take for example a scripts map with {"A" -- D1, "A#L1" -- D1, "A#L0" -- D0}. If a script is removed specified by an id 'A' and lang null then the scripts map will be {"A#L0" -- D0}. To remove the final script, the deprecated namespace must be used, so an id 'A' and lang 'L0' would need to be specified. When a user gets/executes a stored script, if the new namespace is used then the script will be retrieved/executed using only 'id', and if the old namespace is used then the script will be retrieved/executed using 'id' and 'lang'
This commit is contained in:
parent
eb36b82de4
commit
3d2626c4c6
59 changed files with 2963 additions and 1003 deletions
|
@ -54,11 +54,11 @@ GET my_index/_search
|
|||
setting `script.default_lang` to the appropriate language.
|
||||
|
||||
|
||||
`inline`, `id`, `file`::
|
||||
`inline`, `stored`, `file`::
|
||||
|
||||
Specifies the source of the script. An `inline` script is specified
|
||||
`inline` as in the example above, a stored script with the specified `id`
|
||||
is retrieved from the cluster state (see <<modules-scripting-stored-scripts,Stored Scripts>>),
|
||||
`inline` as in the example above, a `stored` script is specified `stored`
|
||||
and is retrieved from the cluster state (see <<modules-scripting-stored-scripts,Stored Scripts>>),
|
||||
and a `file` script is retrieved from a file in the `config/scripts`
|
||||
directory (see <<modules-scripting-file-scripts, File Scripts>>).
|
||||
+
|
||||
|
@ -164,7 +164,6 @@ hierarchy of directories is flattened and concatenated with underscores. A
|
|||
script in `group1/group2/my_script.painless` should use `group1_group2_myscript`
|
||||
as the `file` name.
|
||||
|
||||
|
||||
[[reload-scripts]]
|
||||
[float]
|
||||
==== Automatic script reloading
|
||||
|
@ -181,23 +180,51 @@ Script reloading can be completely disabled by setting
|
|||
=== Stored Scripts
|
||||
|
||||
Scripts may be stored in and retrieved from the cluster state using the
|
||||
`_scripts` end-point:
|
||||
`_scripts` end-point.
|
||||
|
||||
==== Deprecated Namespace
|
||||
|
||||
The namespace for stored scripts using both `lang` and `id` as a unique
|
||||
identifier has been deprecated. The new namespace for stored scripts will
|
||||
only use `id`. Stored scripts with the same `id`, but different `lang`'s
|
||||
will no longer be allowed in 6.0. To comply with the new namespace for
|
||||
stored scripts, existing stored scripts should be deleted and put again.
|
||||
Any scripts that share an `id` but have different `lang`s will need to
|
||||
be re-named. For example, take the following:
|
||||
|
||||
"id": "example", "lang": "painless"
|
||||
"id": "example", "lang": "expressions"
|
||||
|
||||
The above scripts will conflict under the new namespace since the id's are
|
||||
the same. At least one will have to be re-named to comply with the new
|
||||
namespace of only `id`.
|
||||
|
||||
As a final caveat, stored search templates and stored scripts share
|
||||
the same namespace, so if a search template has the same `id` as a
|
||||
stored script, one of the two will have to be re-named as well using
|
||||
delete and put requests.
|
||||
|
||||
==== Request Examples
|
||||
|
||||
The following are examples of stored script requests:
|
||||
|
||||
[source,js]
|
||||
-----------------------------------
|
||||
/_scripts/{lang}/{id} <1> <2>
|
||||
/_scripts/{id} <1>
|
||||
-----------------------------------
|
||||
<1> The `lang` represents the script language.
|
||||
<2> The `id` is a unique identifier or script name.
|
||||
<1> The `id` is a unique identifier for the stored script.
|
||||
|
||||
This example stores a Painless script called `calculate-score` in the cluster
|
||||
state:
|
||||
|
||||
[source,js]
|
||||
-----------------------------------
|
||||
POST _scripts/painless/calculate-score
|
||||
POST _scripts/calculate-score
|
||||
{
|
||||
"script": "Math.log(_score * 2) + params.my_modifier"
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"code": "Math.log(_score * 2) + params.my_modifier"
|
||||
}
|
||||
}
|
||||
-----------------------------------
|
||||
// CONSOLE
|
||||
|
@ -206,12 +233,12 @@ This same script can be retrieved with:
|
|||
|
||||
[source,js]
|
||||
-----------------------------------
|
||||
GET _scripts/painless/calculate-score
|
||||
GET _scripts/calculate-score
|
||||
-----------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
||||
Stored scripts can be used by specifying the `lang` and `stored` parameters as follows:
|
||||
Stored scripts can be used by specifying the `stored` parameters as follows:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
|
@ -220,7 +247,6 @@ GET _search
|
|||
"query": {
|
||||
"script": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"stored": "calculate-score",
|
||||
"params": {
|
||||
"my_modifier": 2
|
||||
|
@ -237,7 +263,7 @@ And deleted with:
|
|||
|
||||
[source,js]
|
||||
-----------------------------------
|
||||
DELETE _scripts/painless/calculate-score
|
||||
DELETE _scripts/calculate-score
|
||||
-----------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue