OpenSearch/docs/java-api/query-dsl/script-query.asciidoc
David Pilato 11a6248344 Update script query doc for 5.1
From 5.1, we changed the order of Script class ctor.

Related to https://github.com/elastic/elasticsearch/pull/21321#issuecomment-266432519
2016-12-14 11:36:55 +01:00

38 lines
1.1 KiB
Plaintext

[[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 `myscript.painless` with:
[source,painless]
--------------------------------------------------
doc['num1'].value > params.param1
--------------------------------------------------
You can use it then with:
[source,java]
--------------------------------------------------
QueryBuilder qb = scriptQuery(
new Script(
ScriptType.FILE, <1>
"painless", <2>
"myscript", <3>
Collections.singletonMap("param1", 5)) <4>
);
--------------------------------------------------
<1> Script type: either `ScriptType.FILE`, `ScriptType.INLINE` or `ScriptType.INDEXED`
<2> Scripting engine
<3> Script name
<4> Parameters as a `Map` of `<String, Object>`