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