mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 04:58:50 +00:00
a03b6c2fa5
This commit adds back "id" as the key within a script to specify a stored script (which with file scripts now gone is no longer ambiguous). It also adds "source" as a replacement for "code". This is in an attempt to normalize how scripts are specified across both put stored scripts and script usages, including search template requests. This also deprecates the old inline/stored keys.
58 lines
1.4 KiB
Plaintext
58 lines
1.4 KiB
Plaintext
[[query-dsl-script-query]]
|
|
=== Script Query
|
|
|
|
A query allowing to define
|
|
<<modules-scripting,scripts>> as queries. They are typically used in a filter
|
|
context, for example:
|
|
|
|
[source,js]
|
|
----------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"bool" : {
|
|
"must" : {
|
|
"script" : {
|
|
"script" : {
|
|
"source": "doc['num1'].value > 1",
|
|
"lang": "painless"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
----------------------------------------------
|
|
// CONSOLE
|
|
|
|
[float]
|
|
==== Custom Parameters
|
|
|
|
Scripts are compiled and cached for faster execution. If the same script
|
|
can be used, just with different parameters provider, it is preferable
|
|
to use the ability to pass parameters to the script itself, for example:
|
|
|
|
[source,js]
|
|
----------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"bool" : {
|
|
"must" : {
|
|
"script" : {
|
|
"script" : {
|
|
"source" : "doc['num1'].value > params.param1",
|
|
"lang" : "painless",
|
|
"params" : {
|
|
"param1" : 5
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
----------------------------------------------
|
|
// CONSOLE
|
|
|