我有一个elasticsearch文档
{ "_index": "testindex", "_type": "testtype", "_id": "doc1", "_version": 1, "found": true, "_source": { "array": [ "abc", "def", "ghi" ] } }
如何反转文档中数组中的所有字符串?我尝试使用下面的脚本更新api
temp = []; for(String item : ctx._source.array) temp << item.reverse(); ctx._source.array = temp;
在java中更新api:
new org.elasticsearch.action.update.UpdateRequest(index, type, docId).script(script);我得到了一个异常,比如脚本中不允许的方法调用。
Bulk request failure, id: [doc4], message: ElasticsearchIllegalArgumentException[failed to execute script]; nested: GroovyScriptCompilationException[MultipleCompilationErrorsException[startup failed:
General error during canonicalization: Method calls not allowed on [java.lang.String]发布于 2016-05-23 21:17:19

尝尝这个
temp=[];
ctx._source.array.each{
it -> temp.add(it.reverse())
}
ctx._source.array = temphttps://stackoverflow.com/questions/37391474
复制相似问题