Adding data in the ctx

Hello

It appears that we can store the data in the ctx.vars for the particular execution context, how do I add it? ( groovy novice). Also, will the information be stored in the watch_history?

Please help, any pointers to script examples for watcher will also help.

Thanks in advance

Any script in a watch can add variables to the context. For example something like this can be added to a script condition: ctx.vars.my_var=5; return ctx.vars.my_var <= 5;

Once a context variable has been defined it is accessible in all places of a Watch that supports scripting. So in the above example the ctx.vars.my_var can also be checked in a script transform elsewhere in the Watch.

Context variables are scoped to the watch execution to are defined in. Context variables aren't stored in the watch history. However when using the execute watch api to test/debug a watch, the context vars can be included in the response if the debug option is specified.

Thanks. I was expecting that the values get stored in the vars in watch_history and hence was not sure.
That helped.

Hello Martijn

Where do we specify the debug option?

The execute watch rest api is described here: https://www.elastic.co/guide/en/watcher/current/api-rest.html#api-rest-execute-watch

But the debug option isn't described there, but you can just append debug=true to the query string of the url.

Thanks