Script condition and ctx.vars

alerting

(Mcku) #1

Hello All,

ES 2.1.1. I am keeping some state info in ctx.vars, set in a transform.

Then check for some conditions in ctx.vars,
apparently can't be accessed within condition script,
but can be accessed within actions and subsequent inputs.

transform": {
 "chain":[ 
  {       
    "script":  "ctx.vars.userid = ctx.payload.hits.hits[0]._source.user.id; ctx.vars.lang = ctx.payload.hits.hits[0]._source.lang;"          
  },

the following returns true (note the hard-coded 'tr') :

"condition": {
  "script" : "return ctx.payload.hits.hits[0]._source.lang.equals('tr') ; " 
},

but this is not.

 "condition": {
  "script" : "return ctx.vars.lang.equals('tr') ; " 
},

However, in actions, i can access ctx.vars without any issue.
I think somehow condition cannot read ctx.var.
Could anyone confirm?

Thx


(Alexander Reelsen) #2

Hey,

a transform is only supposed to modify the payload. You should have access to that in the actions as well and/or use a chained input?

Wondering about the use-case here, interested in the example to see what does not work that way.

--Alex


(Mcku) #3

Actually, I was inspired by this post:

As a transform and conditionsupports scripting, they should have access to ctx.vars. Is this falsified already or still valid, wondering, especially the vendor perspective would be important here as this is a commercial component.

The use case is very significant I think, such as increasing dimensionality of watch evaluations by causal relationships. In that sense, chain inputs and chain transforms together would provide with huge flexibility and would expand the usability of watcher, which is a huge step. Kudos for that.
(But at my small step here now, I am still kinda stuck!)

Thanks anyway...


(Mcku) #4

I am still doing some more tests on that but my eval license has expired :shame: .


(Mcku) #5

After some workarounds, I realize a powerful event processor is ready. Thanks for your support.


(Alexander Reelsen) #6

Hey,

happy to hear, you got it working. If you have an interesting use-case to share, we are all ears :slight_smile:

--Alex


(system) #7