【问题标题】:Groovy property not recognized in ElasticSearch Watcher Transform Script getting proper JSON获取正确 JSON 的 ElasticSearch Watcher 转换脚本中无法识别 Groovy 属性
【发布时间】: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


    【解决方案1】:

    所以,我在 Elasticsearch 存储库中打开了一个 issue。经过一番讨论,将在 mustache 模板引擎中实现原生 toJson 函数,因此它默认呈现 json。

    Here 是拉取请求。

    希望在下一个版本中准备就绪。

    【讨论】:

      猜你喜欢
      • 2016-09-23
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多