Script update with array method unique() causing error

Constantine Bateruk

I need to update array value with another array and then remove intersections, so I found this method 'unique()' for elasticsearch scripts, but it's causing error:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[probook][127.0.0.1:9300][indices:data/write/update[s]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "failed to execute script",
    "caused_by": {
      "type": "script_exception",
      "reason": "runtime error",
      "script_stack": [
        "ctx._source.arrFieldName = ctx._source.arrFieldName.unique();",
        "                                                     ^---- HERE"
      ],
      "script": "ctx._source.arrFieldName.addAll([111, 222, 333]);ctx._source.arrFieldName = ctx._source.arrFieldName.unique();ctx._source.arrFieldNameCount = ctx._source.arrFieldName.length",
      "lang": "painless",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "dynamic method [java.util.ArrayList, unique/0] not found"
      }
    }
  },
  "status": 400
}
Always Sunny

You should do it this way with distinct() instead of unique() for your inline painless script,

{
  "script" : {
      "inline": "ctx._source.arrFieldName=
                ctx._source.arrFieldName.stream().distinct().sorted()
                                      .collect(Collectors.toList())"
 }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

FacebookShare causing compiler error after update

What is causing ERROR: there is no unique constraint matching given keys for referenced table?

Bootstrap datepicker update method causing issues

django __init__ method causing argument error

Calling index of an array in loop causing error

Putting array in render html causing syntax error

Method reference in attribute before method is defined causing error

How can I update adword-customizer data using google app script. (previously uploaded source are causing error)

React - handleChange method not firing causing selected option name not to update

c# out causing a no overload for method error?

How do you find which script is causing the CSP error?

Undefined method `update' for Array

What is causing a "word not bound to context" error in this script?

Calling method is causing Error creating LLDB target

bash: Why are () causing error in script but not on the command line?

Array index out of bounds and causing error?

'if' statement causing 'syntax error near unexpected token `done'' in bash script

update-php class causing 500 internal server error

Array[index + 1] causing the program FATAL error

Laravel Update Method Error

push method in a loop causing array inside of array

Update Unique for One Field in Array

lambda deleter for unique_ptr causing compile error vs functor

Laravel Database Migration Column altered to Unique and Nullable causing error

React component toggle method causing `Uncaught Invariant Violation: Maximum update depth exceeded.` error

Static method is causing an unexpected indent error?

Update double nested array script

Update_or_create method with unique field in Django

Powershell script causing Selenium Edge WebDriver's 'FindElementBy' method error