2015-06-24 17:27:19 -04:00
|
|
|
[[java-query-dsl-script-query]]
|
|
|
|
==== Script Query
|
|
|
|
|
|
|
|
See {ref}/query-dsl-script-query.html[Script Query]
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
QueryBuilder qb = scriptQuery(
|
|
|
|
new Script("doc['num1'].value > 1") <1>
|
|
|
|
);
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> inlined script
|
|
|
|
|
|
|
|
|
2016-06-27 09:55:16 -04:00
|
|
|
If you have stored on each data node a script named `myscript.painless` with:
|
2015-06-24 17:27:19 -04:00
|
|
|
|
2016-08-26 15:59:45 -04:00
|
|
|
[source,painless]
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
2016-06-27 09:55:16 -04:00
|
|
|
doc['num1'].value > params.param1
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
You can use it then with:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
QueryBuilder qb = scriptQuery(
|
|
|
|
new Script(
|
2016-12-12 08:41:42 -05:00
|
|
|
ScriptType.FILE, <1>
|
|
|
|
"painless", <2>
|
|
|
|
"myscript", <3>
|
2016-11-28 11:33:40 -05:00
|
|
|
Collections.singletonMap("param1", 5)) <4>
|
2015-06-24 17:27:19 -04:00
|
|
|
);
|
|
|
|
--------------------------------------------------
|
2016-12-12 08:41:42 -05:00
|
|
|
<1> Script type: either `ScriptType.FILE`, `ScriptType.INLINE` or `ScriptType.INDEXED`
|
|
|
|
<2> Scripting engine
|
|
|
|
<3> Script name
|
2015-06-24 17:27:19 -04:00
|
|
|
<4> Parameters as a `Map` of `<String, Object>`
|