Browse Source

CONSOLEify the "using scripts" documentation

I found an error in one of the Painless scripts as part of
the conversion.

Relates to #18160
Nik Everett 8 years ago
parent
commit
9d2293b381

+ 1 - 1
docs/build.gradle

@@ -88,7 +88,6 @@ buildRestTests.expectedUnconvertedCandidates = [
   'reference/mapping/types/object.asciidoc',
   'reference/mapping/types/percolator.asciidoc',
   'reference/modules/scripting/security.asciidoc',
-  'reference/modules/scripting/using.asciidoc',
   'reference/modules/cross-cluster-search.asciidoc', // this is hard to test since we need 2 clusters -- maybe we can trick it into referencing itself...
   'reference/query-dsl/function-score-query.asciidoc',
   'reference/search/field-stats.asciidoc',
@@ -107,6 +106,7 @@ integTestCluster {
   Closure configFile = {
     extraConfigFile it, "src/test/cluster/config/$it"
   }
+  configFile 'scripts/calculate_score.painless'
   configFile 'scripts/my_script.painless'
   configFile 'scripts/my_init_script.painless'
   configFile 'scripts/my_map_script.painless'

+ 10 - 11
docs/reference/modules/scripting/using.asciidoc

@@ -12,6 +12,7 @@ the same pattern:
     "params": { ... } <3>
   }
 -------------------------------------
+// NOTCONSOLE
 <1> The language the script is written in, which defaults to `painless`.
 <2> The script itself which may be specified as `inline`, `stored`, or `file`.
 <3> Any named parameters that should be passed into the script.
@@ -89,6 +90,7 @@ multipliers, don't hard-code the multiplier into the script:
 ----------------------
   "inline": "doc['my_field'] * 2"
 ----------------------
+// NOTCONSOLE
 
 Instead, pass it in as a named parameter:
 
@@ -99,6 +101,7 @@ Instead, pass it in as a named parameter:
     "multiplier": 2
   }
 ----------------------
+// NOTCONSOLE
 
 The first version has to be recompiled every time the multiplier changes.  The
 second version is only compiled once.
@@ -134,7 +137,7 @@ the following example creates a Groovy script called `calculate-score`:
 
 [source,sh]
 --------------------------------------------------
-cat "Math.log(_score * 2) + my_modifier" > config/scripts/calculate-score.painless
+cat "Math.log(_score * 2) + params.my_modifier" > config/scripts/calculate_score.painless
 --------------------------------------------------
 
 This script can be used as follows:
@@ -147,7 +150,7 @@ GET my_index/_search
     "script": {
       "script": {
         "lang":   "painless", <1>
-        "file":   "calculate-score", <2>
+        "file":   "calculate_score", <2>
         "params": {
           "my_modifier": 2
         }
@@ -156,6 +159,8 @@ GET my_index/_search
   }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[continued]
 <1> The language of the script, which should correspond with the script file suffix.
 <2> The name of the script, which should be the name of the file.
 
@@ -206,16 +211,10 @@ delete and put requests.
 
 ==== Request Examples
 
-The following are examples of stored script requests:
-
-[source,js]
------------------------------------
-/_scripts/{id} <1>
------------------------------------
-<1> The `id` is a unique identifier for the stored script.
+The following are examples of using a stored script that lives at
+`/_scripts/{id}`.
 
-This example stores a Painless script called `calculate-score` in the cluster
-state:
+First, create the script called `calculate-score` in the cluster state:
 
 [source,js]
 -----------------------------------

+ 1 - 0
docs/src/test/cluster/config/scripts/calculate_score.painless

@@ -0,0 +1 @@
+Math.log(_score * 2) + params.my_modifier