要不要也来分享分享一下啊

es5.5版本,执行下面单个的date_histogram或者scripted_metric都是没问题的,但是嵌套起来就报错

Elasticsearch | 作者 王社英 | 发布于2019年01月10日 | 阅读数:1667



{
"aggs": {
"kpi": {
"date_histogram": {
"field": "time",
"interval": "1h"
},
"aggs": {
"kpi": {
"scripted_metric": {
"init_script": "params._agg['subtract'] = []",
"map_script": "params._agg.subtract.add([doc.a.value + doc.b.value,doc.c.value + doc.d.value])",
"combine_script": "double total1=0;double total2=0; for (i in params._agg.subtract) { total1 += i[0]; total2 += i[1] } return [total1, total2]",
"reduce_script": "double total1=0; double total2=0; for (item in params._aggs) { total1 += item[0]; total2 += item[1]} return total1 / total2"
}
}
}
}
}
}

报错信息如下
 
{
"error": {
"root_cause": [],
"type": "search_phase_execution_exception",
"reason": "",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"total1 += item[0]; ",
"^---- HERE"
],
"script": "double total1=0; double total2=0; for (item in params._aggs) { total1 += item[0]; total2 += item[1]} return total1 / total2",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
},
"status": 503
}

 
已邀请:

要回复问题请先登录注册