From 74b2434c2dfd72e595e138cd398bf28ae9ae8b25 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Tue, 25 Jan 2022 10:30:48 -0500 Subject: [PATCH] [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 (cherry picked from commit 3845a418043d9bffd4ff26d037656eb956ec3345) --- .../apis/create-stored-script-api.asciidoc | 13 +++++++++---- .../apis/delete-stored-script-api.asciidoc | 5 +---- .../scripting/apis/get-stored-script-api.asciidoc | 13 +++++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/reference/scripting/apis/create-stored-script-api.asciidoc b/docs/reference/scripting/apis/create-stored-script-api.asciidoc index a53472ce13ba9..6108831a836b1 100644 --- a/docs/reference/scripting/apis/create-stored-script-api.asciidoc +++ b/docs/reference/scripting/apis/create-stored-script-api.asciidoc @@ -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} diff --git a/docs/reference/scripting/apis/delete-stored-script-api.asciidoc b/docs/reference/scripting/apis/delete-stored-script-api.asciidoc index 7d74a7af26d5a..038d1916f76fd 100644 --- a/docs/reference/scripting/apis/delete-stored-script-api.asciidoc +++ b/docs/reference/scripting/apis/delete-stored-script-api.asciidoc @@ -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']" } } ---- diff --git a/docs/reference/scripting/apis/get-stored-script-api.asciidoc b/docs/reference/scripting/apis/get-stored-script-api.asciidoc index f7f974a1f5f1d..6b6f6648a7ed6 100644 --- a/docs/reference/scripting/apis/get-stored-script-api.asciidoc +++ b/docs/reference/scripting/apis/get-stored-script-api.asciidoc @@ -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']" } } ---- @@ -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}