Error While Updating Array using painless script

Hi,
I'm facing issue while updating array field

{ "error": {
"root_cause": [
  {
    "type": "remote_transport_exception",
    "reason": "[3BcGP3Y][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",
  "caused_by": {
    "type": "class_cast_exception",
    "reason": "Cannot apply [+] operation to types [java.util.ArrayList] and [java.util.ArrayList]."
  },
  "script_stack": [
    "ctx._source.stone_ids += params.ids",
    "                               ^---- HERE"
  ],
  "script": "ctx._source.stone_ids += params.ids",
  "lang": "painless"
}}, "status": 400 }

while trying following update operation,
> POST /search_history/stone/2/_update
> {
> "script" : {
> "inline": "ctx._source.stone__ids += params.ids",
> "lang": "painless",
> "params" : {
> "ids" : [4,5]
> }
> },
> "upsert" : {
> "stone_ids":[4,5]
> }
> }

can anyone help me in this?

ctx._source.stone_ids.add(params.ids) should do it.

@nik9000 thank you for reply
I tried with addAll() method it is working properly but with duplicate values.
Is there any settings available to notify that consider this particular field as Set not List to avoid duplication??

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.