我想更新特定字段中的某些值,我希望它是唯一的。無法執行腳本Elasticsearch
但是,當我給腳本條件.unique()它返回一個錯誤。
如果我沒有給出獨特的條件,那麼它會不斷更新。 意味着價值將
update_field =陣列( '世界', '值', '霜', '世界', '值', '霜',...)
我在做什麼這裏錯了有人知道!
$script['script'] = 'ctx._source.update_field = (ctx._source.update_field + new_value).unique()';
// unique() is giving the error but why
錯誤消息---
{ 「錯誤」:「ElasticsearchIllegalArgumentException [未能執行 腳本];嵌套: GroovyScriptExecutionException [MissingMethodException [ 方法的無簽名:java.lang中。 String.unique()適用於參數類型:() values:[] \ n可能的解決方案:minus(java.lang.Object), minus(java.util.regex.Pattern),minus(java.lang.Object ),size(), size(),use([Ljava.lang.Object;)]];「,」status「: 400}
樣本文件---
hits: {
total: 19,
max_score: 5.5197725,
hits: [
{
_index: "myIndex",
_type: "myType",
_id: "pdd9da099f380b3951a627a5d5a38758680016f16",
_score: 5.5197725,
_source: {
content: "After shooting attacks are several police cars sent to the streets to watch.
title: "The police in Copenhagen when bødemål despite extra tasks",
update_field: "[funny]"
}},}
所以你可以看到,update_field不是空的,並有一定的價值 - 時,當我嘗試---
$script['script'] = 'ctx._source.update_field = ((ctx._source.update_field ?: []) - new_value).unique()';
它也會返回相同的錯誤! 不知道爲什麼!
感謝您的答案和解釋,但它也返回我同樣的錯誤,我也有一個樣本文檔更新我的問題,能不能請看看,非常感謝 –
你可能需要擦拭你的'myIndex'索引並重新創建它,因爲你的'update_field'已經被索引爲一個字符串,例如''[funny]「'。 – Val
@Oops我的不好,非常感謝Val,非常感謝您的幫助:),你真棒 –