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

54 lines
1.2 KiB
Plaintext
Raw Normal View History

[[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" : "doc['num1'].value > 1"
}
}
}
}
}
----------------------------------------------
// 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" : {
"inline" : "doc['num1'].value > param1",
"params" : {
"param1" : 5
}
}
}
}
}
}
}
----------------------------------------------
// CONSOLE