【发布时间】:2016-06-17 09:18:50
【问题描述】:
我正在使用:
- 弹性搜索 2.3
- 观察者
- 热门音乐
我们的目标是创建一个手表,每隔 x 时间进行一次查询并检索一些命中,然后将其发布到网络服务器。这工作正常。但是,{{ctx.payload.hits.hits}} 中的 Json 响应不是 Json,所以我无法处理它。同样的问题似乎出现在某些线程中,这与mine 最相似:
所以,这是我的手表(输入正常,问题出在动作脚本中):
PUT _watcher/watch/running_process_watch
{
"trigger" : {
"schedule" : {
"interval" : "10s"
}
},
"input" : {... },
"actions" : {
"ping_webhook": {
"transform":{
"script": "return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]"
},
"webhook": {
"method": "POST",
"host": "localhost",
"port": 4567,
"path": "/register_data",
"headers": {
"Content-Type" : "application/json"
},
"body" : "data: {{ctx.payload.body}}"
}
}
}
}
错误:
failed to execute [script] transform for [running_process_watch_0-2016-06-08T17:25:14.162Z]
ScriptException[failed to run inline script [return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]] using lang [groovy]]; nested: MissingPropertyException[No such property: groovy for class: 1605d064acb49c10c464b655dacc9193f4e2e484];
at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:320)
at org.elasticsearch.watcher.transform.script.ExecutableScriptTransform.doExecute(ExecutableScriptTransform.java:74)
at org.elasticsearch.watcher.transform.script.ExecutableScriptTransform.execute(ExecutableScriptTransform.java:60)
at org.elasticsearch.watcher.transform.script.ExecutableScriptTransform.execute(ExecutableScriptTransform.java:41)
at org.elasticsearch.watcher.actions.ActionWrapper.execute(ActionWrapper.java:94)
at org.elasticsearch.watcher.execution.ExecutionService.executeInner(ExecutionService.java:388)
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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
有没有办法让 groovy.json 在观察者动作脚本中可用?或者任何其他从 ctx.hits.hits 返回正确 json 的想法?
【问题讨论】:
标签: json elasticsearch groovy