2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-script-query]]
|
2015-06-03 19:59:22 -04:00
|
|
|
=== Script Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-05-05 02:27:52 -04:00
|
|
|
A query allowing to define
|
2015-09-11 04:35:56 -04:00
|
|
|
<<modules-scripting,scripts>> as queries. They are typically used in a filter
|
|
|
|
context, for example:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
----------------------------------------------
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
==== Custom Parameters
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
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]
|
|
|
|
----------------------------------------------
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-16 18:01:33 -05:00
|
|
|
----------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|