CONSOLEify the "using scripts" documentation

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

Relates to #18160
This commit is contained in:
Nik Everett 2017-04-03 10:14:21 -04:00
parent 8482503f9b
commit 9d2293b381
3 changed files with 12 additions and 12 deletions

View File

@ -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'

View File

@ -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:
The following are examples of using a stored script that lives at
`/_scripts/{id}`.
[source,js]
-----------------------------------
/_scripts/{id} <1>
-----------------------------------
<1> The `id` is a unique identifier for the stored script.
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]
-----------------------------------

View File

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