# Elasticsearch scripted metric aggregation

**URL:** <https://discuss.elastic.co/t/elasticsearch-scripted-metric-aggregation/163662>\
**Category:** Elasticsearch\
**Created:** [January 10, 2019, 6:29am UTC](https://discuss.elastic.co/t/elasticsearch-scripted-metric-aggregation/163662 "2019-01-10T06:29:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cxfcxf](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@cxfcxf](https://discuss.elastic.co/u/cxfcxf)\
**Post date:** [January 10, 2019, 6:29am UTC](https://discuss.elastic.co/t/elasticsearch-scripted-metric-aggregation/163662/1 "2019-01-10T06:29:34Z")

</div>

**(1)when i use scripted metric aggregation,in mapscript source,I put a java.util.set as a map-value,elasticsearch throws an exception**  
{size": 0,  
"aggs": {  
"collision": {  
"scripted\_metric": {  
"init\_script": {  
"source": "params.\_agg.transactions=;",  
"lang": "painless"  
},  
"map\_script": {  
"source":  
"Map m = new HashMap();"+  
"Set set = new HashSet();"+  
"set.add(3);set.add(4);"+  
**"m.put('1',set);"**  
"params.\_agg.transactions.add(m);",  
"lang": "painless"  
}  
}  
}  
}  
}  
(2)result as follows:  
{  
"took": 5,  
"timed\_out": false,  
"\_shards": {  
"total": 2,  
"successful": 1,  
"skipped": 0,  
"failed": 1,  
"failures": [  
{  
"shard": 1,  
"index": "cxf11",  
"node": "CK7EYabxRguenWBXPTcH6Q",  
"reason": {  
"type": "unchecked\_i\_o\_exception",  
"reason": "unchecked\_i\_o\_exception: java.io.IOException: can not write type [class java.util.HashSet]",  
"caused\_by": {  
"type": "i\_o\_exception",  
"reason": "can not write type [class java.util.HashSet]"  
}  
}  
}  
]  
},  
"hits": {  
"total": 6,  
"max\_score": 0,  
"hits":   
},  
"aggregations": {  
"collision": {  
"value": [  
{  
"transactions": [  
{  
"1": [  
3,  
4  
]  
},  
{  
"1": [  
3,  
4  
]  
},  
{  
"1": [  
3,  
4  
]  
},  
{  
"1": [  
3,  
4  
]  
},  
{  
"1": [  
3,  
4  
]  
},  
{  
"1": [  
3,  
4  
]  
}  
]  
}  
]  
}  
}  
}

---

<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:** [February 7, 2019, 6:29am UTC](https://discuss.elastic.co/t/elasticsearch-scripted-metric-aggregation/163662/2 "2019-02-07T06:29:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
