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-11-28 11:33:40 -05:00
|
|
|
"myscript", <1>
|
|
|
|
ScriptType.FILE, <2>
|
|
|
|
"painless", <3>
|
|
|
|
Collections.singletonMap("param1", 5)) <4>
|
2015-06-24 17:27:19 -04:00
|
|
|
);
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Script name
|
|
|
|
<2> Script type: either `ScriptType.FILE`, `ScriptType.INLINE` or `ScriptType.INDEXED`
|
|
|
|
<3> Scripting engine
|
|
|
|
<4> Parameters as a `Map` of `<String, Object>`
|