Skip to content

Commit 8efc92e

Browse files
authored
[DOCS] Fix stored script example snippet (#83056) (#83079)
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)
1 parent 04173a6 commit 8efc92e

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

docs/reference/scripting/apis/create-stored-script-api.asciidoc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ PUT _scripts/my-stored-script
1313
{
1414
"script": {
1515
"lang": "painless",
16-
"source": """
17-
TimestampHour date = doc['@timestamp'].value;
18-
return date.getHour()
19-
"""
16+
"source": "Math.log(_score * 2) + params['my_modifier']"
2017
}
2118
}
2219
----
2320

21+
////
22+
[source,console]
23+
----
24+
DELETE _scripts/my-stored-script
25+
----
26+
// TEST[continued]
27+
////
28+
2429
[[create-stored-script-api-request]]
2530
==== {api-request-title}
2631

docs/reference/scripting/apis/delete-stored-script-api.asciidoc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ PUT _scripts/my-stored-script
1414
{
1515
"script": {
1616
"lang": "painless",
17-
"source": """
18-
TimestampHour date = doc['@timestamp'].value;
19-
return date.getHour()
20-
"""
17+
"source": "Math.log(_score * 2) + params['my_modifier']"
2118
}
2219
}
2320
----

docs/reference/scripting/apis/get-stored-script-api.asciidoc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ PUT _scripts/my-stored-script
1414
{
1515
"script": {
1616
"lang": "painless",
17-
"source": """
18-
TimestampHour date = doc['@timestamp'].value;
19-
return date.getHour()
20-
"""
17+
"source": "Math.log(_score * 2) + params['my_modifier']"
2118
}
2219
}
2320
----
@@ -29,6 +26,14 @@ GET _scripts/my-stored-script
2926
----
3027
// TEST[continued]
3128

29+
////
30+
[source,console]
31+
----
32+
DELETE _scripts/my-stored-script
33+
----
34+
// TEST[continued]
35+
////
36+
3237
[[get-stored-script-api-request]]
3338
==== {api-request-title}
3439

0 commit comments

Comments
 (0)