Scripted update fails with "unsupport_operation_exception: null"

I am seeing an intermittent issue where ES fails to execute a script due to an unsupported_operation_exception.

The whole error looks like this

"error": {
  "type": "illegal_argument_exception",
  "reason": "failed to execute script",
  "caused_by": {
    "type": "script_exception",
    "reason": "runtime error",
	"script_stack": [
	  " = social;\n    }\n}\n",
	  "           ^---- HERE"
    "script": "update-user",
    "lang": "painless",
    "position": {
      "offset": 1744,
      "start": 1723,
      "end": 1794
    "caused_by": {
      "type": "unsupported_operation_exception",
      "reason": "unsupported_operation_exception: null"

The line of code where the issue occurs is here:

if (ctx._source.groups == null) {
    ctx._source.groups = [:]; // set groups to an empty map
} = social;

I have tried many ways to reproduce this but have had no luck and I can't explain how unsupported_operation_exception is occurring.

One theory I have been trying to investigate is that the map is immutable so calling put() results in the unsupported_operation_exception. Is it possible for the map to be immutable and why would it be immutable in some cases and not others?

I have tried to use Debug.explain to show the painless_type of the field but it does not seem to work for maps.

Any insight would be greatly appreciated! :slight_smile:

I was able to confirm the map is immutable by doing the following

try { = social;
} catch (Exception e) {

Debug.explain showed the type was EmptyMap so I updated the conditional to check if the map is null or empty.

I still can't reproduce this locally and it seems to be random when deployed to our different environments so said I would post where I got to in case it helps others.

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