Using scripts within action transform

I have many watches that need access to the same data used in email notifications. This data rarely changes, but when it does change all watches need to consistently use the same data within a few minutes.

My first attempt at this was to create a simple script that populated a ctx.metadata value

POST /_scripts/groovy/DemoScript
{
"script":"ctx.metadata.DemoValue='Hello'"
}

the script was then executed as a transform in the watcher action. The ctx.metadata value was then used in email text

"actions" :
{
"send_email" :
{
"transform":
{
"script": { "id" : "DemoScript" }
},
"email" :
{
"to" : ["test@test.com"],
"subject" : "Shared Script Test",
"body" : "Shared Script Value = {{ctx.metadata.ctx.metadata.DemoValue}}"

This all works fine except that when I want to change the value of ctx.metadata by updating the script like below the old value is still being used by the watches until I re-POST them or restart elasticsearch

POST /_scripts/groovy/DemoScript
{
"script":"ctx.metadata.DemoValue='Hello World'"
}

There are a lot of watches and I won't necessarily know which watches rely on the script beforehand. I don't want to have to re-POST watches or restart Elasticsearch whenever the script changes. Is there a mechanism that tells Elasticsearch to rebuild the cached script? If I'm going about this wrong I'm open to better ideas

Is anyone able to provide insight into this issue ? I'm happy to provide more information if it helps.

Hey,

you have indeed found a bug here, where watcher does not update the script before execution - I will investigate this and come back with a bugfix hopefully soon.

In the meantime a not too nice workaround would be to use a chained input, and query or GET a certain document in a certain index that contains this desired value.

--Alex

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