0

I'm new to groovy. I've written the simple program which is used in elasticsearch watcher condition, but it is getting an exception MissingMethodException after the FOR IN log statement.

FOR IN
[2016-09-08 16:42:42,654][ERROR][watcher.condition.script ] [elk-node] failed to execute [script] condition for [testwatch_12-2016-09-08T16:42:42.608Z]
ScriptException[failed to run file script [validateScore] using lang [groovy]]; nested: MissingMethodException[No signature of method: de52a242cfec68298fc9cbef740d5b0e4d4112b0.$() is applicable for argument types: (de52a242cfec68298fc9cbef740d5b0e4d4112b0$_run_closure1) values: [de52a242cfec68298fc9cbef740d5b0e4d4112b0$_run_closure1@31787094]
Possible solutions: is(java.lang.Object), run(), run(), any(), use([Ljava.lang.Object;), any(groovy.lang.Closure)];
        at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:320)
        at org.elasticsearch.watcher.condition.script.ExecutableScriptCondition.doExecute(ExecutableScriptCondition.java:67)
        at org.elasticsearch.watcher.condition.script.ExecutableScriptCondition.execute(ExecutableScriptCondition.java:54)
        at org.elasticsearch.watcher.condition.script.ExecutableScriptCondition.execute(ExecutableScriptCondition.java:36)
        at org.elasticsearch.watcher.execution.ExecutionService.executeInner(ExecutionService.java:368)
        at org.elasticsearch.watcher.execution.ExecutionService.execute(ExecutionService.java:273)
        at org.elasticsearch.watcher.execution.ExecutionService$WatchExecutionTask.run(ExecutionService.java:438)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
def thres = ${threshold}
println "${ctx.payload.hits.hits[0]._score}"
def result = false
def score = ${hit._score}


for(hit in ctx.payload.hits.hits){
  println "FOR IN"
  if (${score} > ${thres}) {
    println "Inside Condition IF"
    result = true
  }
}

ElasticSearch Watcher Condision

"condition": { "script" : { "file" : "validateScore", "lang": "groovy", "params" : { "threshold" : 1.09 } } },

2 Answers 2

1

As you define thres and score as variables in the script you don't need to use ${} form to get their values

replace if (${score} > ${thres}) with if (score > thres)

Sign up to request clarification or add additional context in comments.

Comments

0

FYI this may be a better solution for you

result = ctx.payload.hits.hits.any { score > thres }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.