Sending context variable values as a parameter to a stored script

I'm copying this message here since I sended it to ElasticSearch support on 9/4 but I have still no answers.

Thanks.


Hello.

I'm creating watchers on ES. Since they will post a standard structure to a webhook I've created a stored script that takes a few parameters and stores them JSON structured in a context var.

Sometimes I need to use a context value to form a parameter. Let's see a case.

This is my script:

POST _scripts/jmdlcbtestscript001
{
"script": {
"lang": "painless",
"source": "ArrayList whbody = new ArrayList(); whbody.add(['alert_name':params.alert_name]); return ['cuerpo': whbody[0]]"
}
}

And this is the way I'm calling it:

"actions": {
"my-logging-action": {
"transform": {
"script": {
"lang": "painless",
"source": "jmdlcbtestscript001",
"params": {
"alert_name": "Alert Name",
}
}
},
"webhook" : {
"method" : "POST",
"url" : "https://myurl/api/alarms/push/",
"body" : "{{[#toJson](javascript:void(0);)}}ctx.payload.cuerpo{{/toJson}}"
}
}
}

So, now I want to name my alert like this:

"alert_name": "Limit reached - {{ctx.payload.hits.total}} hits.",

If I add this to params "{{ctx.payload.hits.total}}" is sent as string. I tried using keyword script in various ways without success.

How can I do what I need?

Thanks.
Juan Matías

Hi Juan,

See: Watcher Hits in Script Params for a discussion around this. Where the comment was that there is no need to pass parameters around, you have full access to the ctx field in a script transform anyway.

HTH!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.