2016-05-23 9 views
2

私はelasticsearchドキュメント私は文書で、アレイ内のすべての文字列を逆にするにはどうすればよいgroovyスクリプトを使用してelasticsearch文書の配列内のすべての文字列を逆にするにはどうすればよいですか?

{ "_index": "testindex", "_type": "testtype", "_id": "doc1", "_version": 1, "found": true, "_source": { "array": [ "abc", "def", "ghi" ] } }

がありますか?私はスクリプト内で許可されていないメソッド呼び出しのような例外を取得しています

new org.elasticsearch.action.update.UpdateRequest(index, type, docId).script(script); 

:私は次のスクリプト

temp = []; for(String item : ctx._source.array) temp << item.reverse(); ctx._source.array = temp;

JavaでアップデートAPIで更新APIを使用してみました。

答えて

0

click too see the pic 例外が原因でグルーヴィーなスクリプト内のリバース()関数の使い方のスローされます。この

temp=[]; 

ctx._source.array.each{ 

    it -> temp.add(it.reverse()) 
} 

ctx._source.array = temp 
+0

を試してみてください。 –

+0

その解決策の男は、スクリーンショットを添付させてください –

+0

私はそれが正当なgroovyスクリプトであることに同意します。しかし、私はelasticsearch update apiと一緒に同じスクリプトを書いたとき、私は上記の例外があります。 –

関連する問題