# KIbana 4 scripted-metric-aggregation

**URL:** <https://discuss.elastic.co/t/kibana-4-scripted-metric-aggregation/20692>\
**Category:** Elasticsearch\
**Created:** [November 11, 2014, 3:58pm UTC](https://discuss.elastic.co/t/kibana-4-scripted-metric-aggregation/20692 "2014-11-11T15:58:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivan\_morozov](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@ivan\_morozov](https://discuss.elastic.co/u/ivan_morozov)\
**Post date:** [November 11, 2014, 3:58pm UTC](https://discuss.elastic.co/t/kibana-4-scripted-metric-aggregation/20692/1 "2014-11-11T15:58:50Z")

</div>

Hi @ All

First of all, Kibana 4 beta looks very nice, great work!

I'm trying to use the experimental groovy code scripting engine

What i try:

curl -XPOST '[http://localhost:9200/info/\_search](http://localhost:9200/info/_search)' -d '{  
"query": {  
"match\_all" : {}  
},  
"aggs": {  
"result": {  
"scripted\_metric": {  
"init\_script" : "\_agg['res'] = []",  
"map\_script" : "{ \_agg.res.add( doc['checkoutAmount'] ? :  
0) }"  
}  
}  
}  
}'

What i get

{"error":"SearchPhaseExecutionException[Failed to execute phase [query],  
all shards failed; shardFailures {[GlMPEwZFTbONlt0MdqqQIQ][sessioninfo][0]:  
GroovyScriptExecutionException[MissingPropertyException[No such property:  
res for class: Script32]]}{[GlMPEwZFTbONlt0MdqqQIQ][sessioninfo][1]:  
GroovyScriptExecutionException[MissingPropertyException[No such property:  
res for class: Script31]]}{[GlMPEwZFTbONlt0MdqqQIQ][sessioninfo][2]:  
GroovyScriptExecutionException[MissingPropertyException[No such property:  
res for class: Script33]]}{[GlMPEwZFTbONlt0MdqqQIQ][sessioninfo][3]:  
GroovyScriptExecutionException[MissingPropertyException[No such property:  
res for class: Script34]]}{[GlMPEwZFTbONlt0MdqqQIQ][sessioninfo][4]:  
GroovyScriptExecutionException[MissingPropertyException[No such property:  
res for class: Script35]]}]","status":400}

i think it went something wrong in the "init\_script" line.

Anyone a hint what i do wrong?

Ivan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7081fb00-40aa-4a0c-b5fb-f9e36bf494ee%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7081fb00-40aa-4a0c-b5fb-f9e36bf494ee%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ivan\_morozov](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@ivan\_morozov](https://discuss.elastic.co/u/ivan_morozov)\
**Post date:** [November 11, 2014, 4:07pm UTC](https://discuss.elastic.co/t/kibana-4-scripted-metric-aggregation/20692/2 "2014-11-11T16:07:02Z")

</div>

Got the solution.

The Problem is that groovy code is implemented as a closure so you should  
do it this way:  
"scripted\_metric": {  
"init\_script" : "{\_agg -\> \_agg['res'] = []}",  
"map\_script" : "{\_agg -\> \_agg.res.add(  
doc['checkoutAmount'] ?: 0) }"  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/69cc3db4-c9db-489e-a0db-643a526d1c00%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/69cc3db4-c9db-489e-a0db-643a526d1c00%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:50am UTC](https://discuss.elastic.co/t/kibana-4-scripted-metric-aggregation/20692/3 "2017-07-06T00:50:48Z")

</div>


