How to create an array runtime field

I've managed to achieve the array result defining a script field on the dataView as follow:

def names = new String[params._source.roles.length];
def i= 0;
for( role in params._source.roles){
  if(role.name != null){
    names[i++] = role.name;
  }
}
return names;

Add this script via the Kibana management UI: DataViews > [your dataView] > Click on Scripted fieldstab >Add scripted field`.