Kibana painless scripted fields. Loop on array of objects

sorry, the if statement is broken ....

for(int i=0; i < doc["customer.contact.phones.number.keyword"].values.length;i++){

or if you are using older version of es something like this should work:

def l = new ArrayList();

for(int i=0; i < params._source.customer.contact.phones.length;i++){
  l.add(params._source.customer.contact.phones[i].category +':'+ params._source.customer.contact.phones[i].number])
}

return l.toArray();