Hello,
I wanted to save aggregations results into a new indice to reduce real time calculations on Kibana, so I created a watcher that fetches the result of my pipelined aggregations (4 nested bucket arrays) into one list and indexes it into the new indice, the pipelined buckets are described like this:
ctx.payload.aggregations.agg1.buckets
ctx.payload.aggregations.agg1.buckets.agg2.buckets
ctx.payload.aggregations.agg1.buckets.agg2.buckets.agg3.buckets
ctx.payload.aggregations.agg1.buckets.agg2.buckets.agg3.buckets.agg4.buckets
Here is my transform script
def trips= ArrayList();
for (agg1 in ctx.payload.aggregations.agg1.buckets){
for (agg2 in agg1.agg2.buckets){
for (agg3 in agg2.agg3.buckets){
for (agg4 in agg3.agg4.buckets){
trips.add(['rider_full_name':agg1.key, 'rider_email':agg2.key, 'rider_phone':agg3.key,'rider_id':agg4.key, 'nb_requests':agg4.doc_count,'nb_finished':agg4.nb_finished, 'first_request':agg4.first_request,'last_request':agg4.last_request, 'first_trip':agg4.first_trip, 'last_trip':agg4.last_trip, 'sum_cost':agg4.sum_cost, 'sum_distance':agg4.sum_distance, '@timestamp':agg4.timestamp]);
}
}
}
}
The execution of this script gives me the following error:
Watcher: An internal server error occurred
Any help would be really appreciated Thanks in advance.