【发布时间】:2015-12-24 16:32:23
【问题描述】:
我正在尝试更新特定字段中的一些值,我希望这些值是唯一的。
但是当我给脚本提供条件 .unique() 时,它会返回一个错误。
如果我没有给出唯一的条件,那么它会一次又一次地更新。 表示该值将是
update_field=array('world','values','frost','world','values','frost',...)
我在这里做错了什么谁都知道!!!
$script['script'] = 'ctx._source.update_field = (ctx._source.update_field + new_value).unique()';
// unique() is giving the error but why
错误信息---
{"error":"ElasticsearchIllegalArgumentException[执行失败 脚本];嵌套: GroovyScriptExecutionException[MissingMethodException[没有签名 方法:java.lang.String.unique() 适用于参数类型:() 值:[]\n可能的解决方案:减号(java.lang.Object), 减(java.util.regex.Pattern),减(java.lang.Object),大小(), 大小(),使用([Ljava.lang.Object;)]]; ","状态":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()';
它也会返回同样的错误! 不知道为什么!!
【问题讨论】:
标签: elasticsearch