Hi everyone,
I'm tring to format the result of my scripted metric from seconds to hh:mm:ss
I didn't find any easy way to perform that and i've tried using the reduce script to do so.
Doing this i've got a surprising error telling me ""unexpected token [';'] was expecting one of [].""
the semi-colon mentionned in this error is the one in the reduce script just after the for.
here is the request i used
POST elasticube-1101_homolog-2017.05.15/_search
{
"aggs": {
"profit": {
"scripted_metric": {
"init_script" :
"params._agg.numerator = []; params._agg.denominator = [];"
,
"map_script" :
"params._agg.numerator.add(doc["action.cp"].value); params._agg.denominator.add(doc["action.can"].value + doc["action.cap"].value);"
,
"combine_script" : "int num_sum=0; int den_sum=0; for (t in params._agg.numerator) { num_sum+= t} for (t in params._agg.denominator) { den_sum += t } return ['num_sum': num_sum, 'den_sum': den_sum];",
"reduce_script" : "float num_sum = 0;for (a in params._aggs) {num_sum += a.num_sum;};var h = Math.floor(num_sum / 3600);var m = Math.floor(num_sum % 3600 / 60);var s = Math.floor(num_sum % 3600 % 60);return h + ":" + m + ":" + s;"
}
}
}
}
Can someone help me with formatting my result?