OpenSearch/docs/reference/query-dsl/script-query.asciidoc

76 lines
1.7 KiB
Plaintext
Raw Normal View History

[[query-dsl-script-query]]
=== Script query
++++
<titleabbrev>Script</titleabbrev>
++++
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>>.
[[script-query-ex-request]]
==== Example request
[source,console]
2019-07-29 09:59:09 -04:00
----
GET /_search
{
"query": {
"bool" : {
"filter" : {
"script" : {
2016-06-27 09:55:16 -04:00
"script" : {
"source": "doc['num1'].value > 1",
2016-06-27 09:55:16 -04:00
"lang": "painless"
}
}
}
}
}
}
2019-07-29 09:59:09 -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:
[source,console]
2019-07-29 09:59:09 -04:00
----
GET /_search
{
"query": {
"bool" : {
"filter" : {
"script" : {
"script" : {
"source" : "doc['num1'].value > params.param1",
2016-06-27 09:55:16 -04:00
"lang" : "painless",
"params" : {
"param1" : 5
}
}
}
}
}
}
}
2019-07-29 09:59:09 -04:00
----
===== Allow expensive queries
Script queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
is set to false.