2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-script-query]]
|
2019-07-18 10:18:11 -04:00
|
|
|
=== Script query
|
|
|
|
++++
|
|
|
|
<titleabbrev>Script</titleabbrev>
|
|
|
|
++++
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-29 09:59:09 -04:00
|
|
|
Filters documents based on a provided <<modules-scripting-using,script>>. The
|
|
|
|
`script` query is typically used in a <<query-filter-context,filter context>>.
|
|
|
|
|
2020-07-20 15:05:33 -04:00
|
|
|
WARNING: Using scripts can result in slower search speeds. See
|
|
|
|
<<scripts-and-search-speed>>.
|
|
|
|
|
2019-07-29 09:59:09 -04:00
|
|
|
|
|
|
|
[[script-query-ex-request]]
|
|
|
|
==== Example request
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2019-07-29 09:59:09 -04:00
|
|
|
----
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"bool" : {
|
2018-11-19 10:27:43 -05:00
|
|
|
"filter" : {
|
2016-05-24 05:58:43 -04:00
|
|
|
"script" : {
|
2016-06-27 09:55:16 -04:00
|
|
|
"script" : {
|
2017-06-09 11:29:25 -04:00
|
|
|
"source": "doc['num1'].value > 1",
|
2016-06-27 09:55:16 -04:00
|
|
|
"lang": "painless"
|
|
|
|
}
|
2016-05-24 05:58:43 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-29 09:59:09 -04:00
|
|
|
----
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
|
2019-07-29 09:59:09 -04:00
|
|
|
[[script-top-level-params]]
|
|
|
|
==== Top-level parameters for `script`
|
|
|
|
|
|
|
|
`script`::
|
|
|
|
(Required, <<modules-scripting-using, script object>>) Contains a script to run
|
|
|
|
as a query. This script must return a boolean value, `true` or `false`.
|
|
|
|
|
|
|
|
[[script-query-notes]]
|
|
|
|
==== Notes
|
|
|
|
|
|
|
|
[[script-query-custom-params]]
|
|
|
|
===== Custom Parameters
|
|
|
|
|
|
|
|
Like <<query-filter-context,filters>>, scripts are cached for faster execution.
|
|
|
|
If you frequently change the arguments of a script, we recommend you store them
|
|
|
|
in the script's `params` parameter. For example:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2019-07-29 09:59:09 -04:00
|
|
|
----
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"bool" : {
|
2018-11-19 10:27:43 -05:00
|
|
|
"filter" : {
|
2016-05-24 05:58:43 -04:00
|
|
|
"script" : {
|
|
|
|
"script" : {
|
2017-06-09 11:29:25 -04:00
|
|
|
"source" : "doc['num1'].value > params.param1",
|
2016-06-27 09:55:16 -04:00
|
|
|
"lang" : "painless",
|
2016-05-24 05:58:43 -04:00
|
|
|
"params" : {
|
|
|
|
"param1" : 5
|
|
|
|
}
|
|
|
|
}
|
2015-05-12 05:37:22 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-29 09:59:09 -04:00
|
|
|
----
|
2020-02-12 16:56:14 -05:00
|
|
|
|
|
|
|
===== Allow expensive queries
|
|
|
|
Script queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
|
|
|
|
is set to false.
|