Elasticsearch Scripts将元素添加到数组中

时间:2015-03-06 13:00:39

标签: scala groovy elasticsearch elastic4s

我正在scala项目中处理ElasticSearch。我使用 elastic4s 作为客户端。我试图从迭代器中逐个添加元素到文档。

while (iterator.hasNext) {
  counter +=1
  client.execute {
    update id reportID in "reports/report" script "ctx._source.elasticData += output" params Map("output" -> iterator.next().toStringifiedJson)
  }.await
}

上述代码不起作用,产生以下错误:

    [ERROR] [03/06/2015 14:44:23.515] [SparkActorSystem-akka.actor.default-dispatcher-5] [akka://SparkActorSystem/user/spark-actor] failed to execute script
    org.elasticsearch.ElasticsearchIllegalArgumentException: failed to execute script
        at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:189)
        at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:176)
        at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:170)
        at org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction$AsyncSingleAction$1.run(TransportInstanceSingleOperationAction.java:187)
        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)
    Caused by: org.elasticsearch.ElasticsearchIllegalArgumentException: script_lang not supported [groovy]
        at org.elasticsearch.script.ScriptService.dynamicScriptEnabled(ScriptService.java:521)
        at org.elasticsearch.script.ScriptService.verifyDynamicScripting(ScriptService.java:398)
        [ERROR] [03/06/2015 14:44:23.515] [SparkActorSystem-akka.actor.default-dispatcher-5] [akka://SparkActorSystem/user/spark-actor] failed to execute script
    org.elasticsearch.ElasticsearchIllegalArgumentException: failed to execute script
        at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:189)
        at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:176)
        at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:170)
        at org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction$AsyncSingleAction$1.run(TransportInstanceSingleOperationAction.java:187)
        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)
    Caused by: org.elasticsearch.ElasticsearchIllegalArgumentException: script_lang not supported [groovy]
        at org.elasticsearch.script.ScriptService.dynamicScriptEnabled(ScriptService.java:521)
        at org.elasticsearch.script.ScriptService.verifyDynamicScripting(ScriptService.java:398)
        at org.elasticsearch.script.ScriptService.compile(ScriptService.java:363)
        at org.elasticsearch.script.ScriptService.executable(ScriptService.java:503)
        at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:183)
        ... 6 moreat org.elasticsearch.script.ScriptService.compile(ScriptService.java:363)
        at org.elasticsearch.script.ScriptService.executable(ScriptService.java:503)
        at org.elasticsearch.
action.update.UpdateHelper.prepare(UpdateHelper.java:183)
    ... 6 more

问题在于我假设的脚本,但我找不到任何解决方案。请帮忙......

1 个答案:

答案 0 :(得分:3)

添加groovy依赖是否解决了这个问题?请注意:gist