Skip to content

Commit

Permalink
[DOCS] Fix stored script example snippet (#83056) (#83079)
Browse files Browse the repository at this point in the history
Changes:

* Updates the example Painless script to be valid and aligns it with the example in [How to write a script](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-using.html#script-stored-scripts).
* Adds a hidden snippets to delete the script for cleanup.

Relates to #83038

(cherry picked from commit 3845a41)
  • Loading branch information
jrodewig authored Jan 25, 2022
1 parent 04173a6 commit 8efc92e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
13 changes: 9 additions & 4 deletions docs/reference/scripting/apis/create-stored-script-api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ PUT _scripts/my-stored-script
{
"script": {
"lang": "painless",
"source": """
TimestampHour date = doc['@timestamp'].value;
return date.getHour()
"""
"source": "Math.log(_score * 2) + params['my_modifier']"
}
}
----

////
[source,console]
----
DELETE _scripts/my-stored-script
----
// TEST[continued]
////

[[create-stored-script-api-request]]
==== {api-request-title}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ PUT _scripts/my-stored-script
{
"script": {
"lang": "painless",
"source": """
TimestampHour date = doc['@timestamp'].value;
return date.getHour()
"""
"source": "Math.log(_score * 2) + params['my_modifier']"
}
}
----
Expand Down
13 changes: 9 additions & 4 deletions docs/reference/scripting/apis/get-stored-script-api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ PUT _scripts/my-stored-script
{
"script": {
"lang": "painless",
"source": """
TimestampHour date = doc['@timestamp'].value;
return date.getHour()
"""
"source": "Math.log(_score * 2) + params['my_modifier']"
}
}
----
Expand All @@ -29,6 +26,14 @@ GET _scripts/my-stored-script
----
// TEST[continued]

////
[source,console]
----
DELETE _scripts/my-stored-script
----
// TEST[continued]
////

[[get-stored-script-api-request]]
==== {api-request-title}

Expand Down

0 comments on commit 8efc92e

Please sign in to comment.