Hi,
I have query with aggregation and as result I receive the buckets with the "key" and "doc_count".
I want to send mail for each bucket that is find in the output.
I have this:
"transform": {
"script": {
"source": """
HashMap result = new HashMap();
ArrayList logging_action_tenant = new ArrayList();
ArrayList logging_action_number = new ArrayList();
ArrayList logging_doc_found = ctx.payload.aggregations.0.buckets;
for (int i = 0; i < logging_doc_found.length; i++) {
if (logging_doc_found[i].doc_count > 0) {
result.put(logging_doc_found[i].key, logging_doc_found[i].doc_count );
}
}
return (result);
""",
"lang": "painless"
}
},
"actions": {
"POSTFIX-Send-mail" : {
"foreach" : "ctx.payload._value",
"max_iterations" : 20,
"email": {
"profile": "standard",
"to": [
"test"
],
"subject": " {{ctx.payload}} ",
"body": {
"text": " {{ctx.payload._value}} "
}
}
But receive this error:
"error" : {
"root_cause" : [
{
"type" : "exception",
"reason" : "specified foreach object was null: [ctx.payload._val]"
}
],
"type" : "exception",
"reason" : "specified foreach object was null: [ctx.payload._val]"
}
}
Any idea of possible solution?
thx!