I am trying to update the some values in a particular field, which I want to be unique.
But when I give the script the condition .unique() it returns me an error.
If I do not give the condition unique then it's keep updating again and again. Means the value will be
update_field= array ('world','values','frost','world','values','frost',...)
What I am doing wrong here anyone knows !!!
$script['script'] = 'ctx._source.update_field = (ctx._source.update_field + new_value).unique()';
// unique() is giving the error but why
error message ---
{"error":"ElasticsearchIllegalArgumentException[failed to execute script]; nested: GroovyScriptExecutionException[MissingMethodException[No signature of method: java.lang.String.unique() is applicable for argument types: () values: []\nPossible solutions: minus(java.lang.Object), minus(java.util.regex.Pattern), minus(java.lang.Object), size(), size(), use([Ljava.lang.Object;)]]; ","status":400}
a sample documents ---
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]"
}},}
So there you can see that the update_field is not empty and have some value - when when i try ---
$script['script'] = 'ctx._source.update_field = ((ctx._source.update_field ?: []) - new_value).unique()';
it also returns me the same error ! don't know why !!