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
|
2013-08-28 19:24:34 -04:00
|
|
|
<<modules-scripting,scripts>> as filters. For
|
|
|
|
example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
----------------------------------------------
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
...
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"script" : {
|
|
|
|
"script" : "doc['num1'].value > 1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----------------------------------------------
|
|
|
|
|
|
|
|
[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]
|
|
|
|
----------------------------------------------
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
...
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"script" : {
|
2015-05-12 05:37:22 -04:00
|
|
|
"script" : {
|
|
|
|
"inline" : "doc['num1'].value > param1"
|
|
|
|
"params" : {
|
|
|
|
"param1" : 5
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-16 18:01:33 -05:00
|
|
|
----------------------------------------------
|
2013-08-28 19:24:34 -04:00
|
|
|
|