Hi team,
I'm really getting a hard time working with transform scripts cause it's only allowing me to write on 1 line:
example:
"transform": {
"script": {
"source": " String k; int i; int s; int a; float sar; for(i=0;i<ctx.payload.aggregations.direction.buckets.size();i++){if(ctx.payload.aggregations.direction.buckets[i].key == 'submitted'){s=ctx.payload.aggregations.direction.buckets[i].doc_count;} else {a=ctx.payload.aggregations.direction.buckets[i].doc_count;}} sar=a*100/s;DecimalFormat df = new DecimalFormat('###'); k=df.format(sar); List Result = [ 'Attempted', a, 'Submitted', s, k ]; return Result;",
"lang": "painless"
}
}
=> question : is it possible to have a Carriage return on the script to have something like the following:
"transform": {
"script": {
"source": "
String k;
int i;
int s;
int a;
float sar;
for(i=0;i<ctx.payload.aggregations.direction.buckets.size();i++)
{
if(ctx.payload.aggregations.direction.buckets[i].key == 'submitted')
{
s=ctx.payload.aggregations.direction.buckets[i].doc_count;
}
else
{
a=ctx.payload.aggregations.direction.buckets[i].doc_count;
}
}
sar=a*100/s;
DecimalFormat df = new DecimalFormat('###');
k=df.format(sar);
List Result = [ 'Attempted', a, 'Submitted', s, k ];
return Result;",
"lang": "painless"
}
}
I put """ surrounding the source block.. but saying "Invalid json".
is there a way to do it or put the script in a file and call it??
Thanks