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
|
|
|
|
|
|
|
|
|
|
|
|
If you have stored on each data node a script named `mygroovyscript.groovy` with:
|
|
|
|
|
|
|
|
[source,groovy]
|
|
|
|
--------------------------------------------------
|
|
|
|
doc['num1'].value > param1
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
You can use it then with:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
QueryBuilder qb = scriptQuery(
|
|
|
|
new Script(
|
|
|
|
"mygroovyscript", <1>
|
2015-10-19 06:17:45 -04:00
|
|
|
ScriptType.FILE, <2>
|
2015-06-24 17:27:19 -04:00
|
|
|
"groovy", <3>
|
|
|
|
ImmutableMap.of("param1", 5)) <4>
|
|
|
|
);
|
|
|
|
--------------------------------------------------
|
|
|
|
<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>`
|
|
|
|
|
2015-10-19 06:17:45 -04:00
|
|
|
|