Merge branch 'pr/update-docs-51'
This commit is contained in:
commit
43f9cd1fd4
|
@ -13,42 +13,31 @@ Here is an example on how to create the aggregation request:
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
ScriptedMetricAggregationBuilder aggregation = AggregationBuilders
|
ScriptedMetricAggregationBuilder aggregation = AggregationBuilders
|
||||||
.scriptedMetric("agg")
|
.scriptedMetric("agg")
|
||||||
.initScript(new Script("_agg['heights'] = []"))
|
.initScript(new Script("params._agg.heights = []"))
|
||||||
.mapScript(new Script("if (doc['gender'].value == \"male\") " +
|
.mapScript(new Script("params._agg.heights.add(doc.gender.value == 'male' ? doc.height.value : -1.0 * doc.height.value)"));
|
||||||
"{ _agg.heights.add(doc['height'].value) } " +
|
|
||||||
"else " +
|
|
||||||
"{ _agg.heights.add(-1 * doc['height'].value) }"));
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
You can also specify a `combine` script which will be executed on each shard:
|
You can also specify a `combine` script which will be executed on each shard:
|
||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
ScriptedMetricAggregationBuilder aggregation =
|
ScriptedMetricAggregationBuilder aggregation = AggregationBuilders
|
||||||
AggregationBuilders
|
|
||||||
.scriptedMetric("agg")
|
.scriptedMetric("agg")
|
||||||
.initScript(new Script("_agg['heights'] = []"))
|
.initScript(new Script("params._agg.heights = []"))
|
||||||
.mapScript(new Script("if (doc['gender'].value == \"male\") " +
|
.mapScript(new Script("params._agg.heights.add(doc.gender.value == 'male' ? doc.height.value : -1.0 * doc.height.value)"))
|
||||||
"{ _agg.heights.add(doc['height'].value) } " +
|
.combineScript(new Script("double heights_sum = 0.0; for (t in params._agg.heights) { heights_sum += t } return heights_sum"));
|
||||||
"else " +
|
|
||||||
"{ _agg.heights.add(-1 * doc['height'].value) }"))
|
|
||||||
.combineScript(new Script("heights_sum = 0; for (t in _agg.heights) { heights_sum += t }; return heights_sum"));
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
You can also specify a `reduce` script which will be executed on the node which gets the request:
|
You can also specify a `reduce` script which will be executed on the node which gets the request:
|
||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
ScriptedMetricAggregationBuilder aggregation =
|
ScriptedMetricAggregationBuilder aggregation = AggregationBuilders
|
||||||
AggregationBuilders
|
|
||||||
.scriptedMetric("agg")
|
.scriptedMetric("agg")
|
||||||
.initScript(new Script("_agg['heights'] = []"))
|
.initScript(new Script("params._agg.heights = []"))
|
||||||
.mapScript(new Script("if (doc['gender'].value == \"male\") " +
|
.mapScript(new Script("params._agg.heights.add(doc.gender.value == 'male' ? doc.height.value : -1.0 * doc.height.value)"))
|
||||||
"{ _agg.heights.add(doc['height'].value) } " +
|
.combineScript(new Script("double heights_sum = 0.0; for (t in params._agg.heights) { heights_sum += t } return heights_sum"))
|
||||||
"else " +
|
.reduceScript(new Script("double heights_sum = 0.0; for (a in params._aggs) { heights_sum += a } return heights_sum"));
|
||||||
"{ _agg.heights.add(-1 * doc['height'].value) }"))
|
|
||||||
.combineScript(new Script("heights_sum = 0; for (t in _agg.heights) { heights_sum += t }; return heights_sum"))
|
|
||||||
.reduceScript(new Script("heights_sum = 0; for (a in _aggs) { heights_sum += a }; return heights_sum"));
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,13 @@ You can use it then with:
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
QueryBuilder qb = scriptQuery(
|
QueryBuilder qb = scriptQuery(
|
||||||
new Script(
|
new Script(
|
||||||
"myscript", <1>
|
ScriptType.FILE, <1>
|
||||||
ScriptType.FILE, <2>
|
"painless", <2>
|
||||||
"painless", <3>
|
"myscript", <3>
|
||||||
Collections.singletonMap("param1", 5)) <4>
|
Collections.singletonMap("param1", 5)) <4>
|
||||||
);
|
);
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
<1> Script name
|
<1> Script type: either `ScriptType.FILE`, `ScriptType.INLINE` or `ScriptType.INDEXED`
|
||||||
<2> Script type: either `ScriptType.FILE`, `ScriptType.INLINE` or `ScriptType.INDEXED`
|
<2> Scripting engine
|
||||||
<3> Scripting engine
|
<3> Script name
|
||||||
<4> Parameters as a `Map` of `<String, Object>`
|
<4> Parameters as a `Map` of `<String, Object>`
|
||||||
|
|
|
@ -216,7 +216,7 @@ To execute a stored templates, use `ScriptService.ScriptType.STORED`:
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
SearchResponse sr = new SearchTemplateRequestBuilder(client)
|
SearchResponse sr = new SearchTemplateRequestBuilder(client)
|
||||||
.setScript("template_gender") <1>
|
.setScript("template_gender") <1>
|
||||||
.setScriptType(ScriptService.ScriptType.STORED) <2>
|
.setScriptType(ScriptType.STORED) <2>
|
||||||
.setScriptParams(template_params) <3>
|
.setScriptParams(template_params) <3>
|
||||||
.setRequest(new SearchRequest()) <4>
|
.setRequest(new SearchRequest()) <4>
|
||||||
.get() <5>
|
.get() <5>
|
||||||
|
@ -241,7 +241,7 @@ sr = new SearchTemplateRequestBuilder(client)
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}")
|
"}")
|
||||||
.setScriptType(ScriptService.ScriptType.INLINE) <2>
|
.setScriptType(ScriptType.INLINE) <2>
|
||||||
.setScriptParams(template_params) <3>
|
.setScriptParams(template_params) <3>
|
||||||
.setRequest(new SearchRequest()) <4>
|
.setRequest(new SearchRequest()) <4>
|
||||||
.get() <5>
|
.get() <5>
|
||||||
|
|
Loading…
Reference in New Issue