[DOCS] Fix stored script example snippet (#83056)

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 https://github.com/elastic/elasticsearch/issues/83038
This commit is contained in:
James Rodewig 2022-01-25 10:30:48 -05:00 committed by GitHub
parent b552d5cb0e
commit 3845a41804
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View file

@ -13,14 +13,19 @@ PUT _scripts/my-stored-script
{ {
"script": { "script": {
"lang": "painless", "lang": "painless",
"source": """ "source": "Math.log(_score * 2) + params['my_modifier']"
TimestampHour date = doc['@timestamp'].value;
return date.getHour()
"""
} }
} }
---- ----
////
[source,console]
----
DELETE _scripts/my-stored-script
----
// TEST[continued]
////
[[create-stored-script-api-request]] [[create-stored-script-api-request]]
==== {api-request-title} ==== {api-request-title}

View file

@ -14,10 +14,7 @@ PUT _scripts/my-stored-script
{ {
"script": { "script": {
"lang": "painless", "lang": "painless",
"source": """ "source": "Math.log(_score * 2) + params['my_modifier']"
TimestampHour date = doc['@timestamp'].value;
return date.getHour()
"""
} }
} }
---- ----

View file

@ -14,10 +14,7 @@ PUT _scripts/my-stored-script
{ {
"script": { "script": {
"lang": "painless", "lang": "painless",
"source": """ "source": "Math.log(_score * 2) + params['my_modifier']"
TimestampHour date = doc['@timestamp'].value;
return date.getHour()
"""
} }
} }
---- ----
@ -29,6 +26,14 @@ GET _scripts/my-stored-script
---- ----
// TEST[continued] // TEST[continued]
////
[source,console]
----
DELETE _scripts/my-stored-script
----
// TEST[continued]
////
[[get-stored-script-api-request]] [[get-stored-script-api-request]]
==== {api-request-title} ==== {api-request-title}