I am trying to create a watcher condition, the result of my query is: { 0= {_type=test, _source= {timetaken=46, [...] } }, 1={_type=test, _source= {timetaken=1222, [...] } }, 2={_type=test, _source= {timetaken=5000, [...] } }, [...] }
I goal is to take all results with timetaken > 2000
I wrote this condition, and it is working : "condition" : { "compare" : { "ctx.payload.hits.hits.0._source.timetaken" : { "gt" : 2000 }} }
but it is verifying only the first result.
then I wrote this : "condition" : { "array_compare": { "ctx.payload.hits.hits": { "path": "timetaken" , "gt": { "value": 2000 } } } }
but this is not creating any alert.
what is wrong ?
someone have some clue?
I think you misinterpreted the functionality of the script condition here. First, conditions only exist, to decide if the action should be executed at all. Conditions dont change your search results or anything like that. The above condition simply matches if any of those array elements is greather than 2000.
This still means, that the hits you are getting back can contain anything based on your search.
Wondering why you dont change your query to only contain results with the timetaken threshold and change your condition to have the total hits being returned greater than 0.
The easiest way is to add a scripted transform, which reduced the hits you got to the ones you want. Or just even extract some fields out of that one. So writing a transformation script and then being able to easily process those results in your logging action should be the way to go.
I am trying to use transform "condition" : { "compare" : { "ctx.payload.hits.total" : { "gte" : 1 } } }
but I am receiving this error: "type": "script_exception", "reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits] of type [groovy]" }, "status": 500
my elasticseach.yml is: script.engine.groovy.file.aggs: on script.engine.groovy.file.mapping: on script.engine.groovy.file.search: on script.engine.groovy.file.update: on script.engine.groovy.file.plugin: on script.engine.groovy.indexed.aggs: on script.engine.groovy.indexed.mapping: off script.engine.groovy.indexed.search: on script.engine.groovy.indexed.update: off script.engine.groovy.indexed.plugin: off script.engine.groovy.inline.aggs: on script.engine.groovy.inline.mapping: off script.engine.groovy.inline.search: off script.engine.groovy.inline.update: on script.engine.groovy.inline.plugin: off
is it possible, that your watch has somewhere else some scripting part? Can you post the complete watch? Maybe using markdown formatting features like ```, so it is easier to follow
"root_cause": [
{
"type": "script_exception",
"reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits] of type [groovy]"
}
],
"type": "script_exception",
"reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits] f type [groovy]"
},
"status": 500
}`
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.