Script transform gives an internal server error in watcher

For those who got a similar issue, it was actually a syntax error in my loop code, solved my problem by using the following script:

def trips= ArrayList();
for (def agg1 : ctx.payload.aggregations.agg1.buckets){ 
  for (def agg2 : agg1.agg2.buckets){ 
    for (def agg3 : agg2.agg3.buckets){ 
       for (def agg4 : 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'].value, 'first_request':agg4['first_request'].value_as_string,'last_request':agg4['last_request'].value_as_string, 'first_trip':agg4['first_trip'].value_as_string, 'last_trip':agg4['last_trip'].value_as_string, 'sum_cost':agg4['sum_cost'].value, 'sum_distance':agg4['sum_distance'].value, '@timestamp':agg4['timestamp'].value_as_string]);
       }
    }
  }
}