# Scripted update fails with "unsupport\_operation\_exception: null"

**URL:** https://discuss.elastic.co/t/scripted-update-fails-with-unsupport-operation-exception-null/344349
**Category:** Elasticsearch
**Tags:** painless, runtime-fields
**Created:** [October 3, 2023, 9:38pm UTC](https://discuss.elastic.co/t/scripted-update-fails-with-unsupport-operation-exception-null/344349 "2023-10-03T21:38:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![s.moran](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@s.moran](https://discuss.elastic.co/u/s.moran)
#### Post date: [October 3, 2023, 9:38pm UTC](https://discuss.elastic.co/t/scripted-update-fails-with-unsupport-operation-exception-null/344349/1 "2023-10-03T21:38:17Z")

</div>

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

```auto
"error": {
  "type": "illegal_argument_exception",
  "reason": "failed to execute script",
  "caused_by": {
    "type": "script_exception",
    "reason": "runtime error",
	"script_stack": [
	  "java.base/java.util.AbstractMap.put(AbstractMap.java:209)",
	  "ctx._source.groups.social = 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:

```auto
if (ctx._source.groups == null) {
    ctx._source.groups = [:]; // set groups to an empty map
}
ctx._source.groups.social = 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! 🙂

---

<div class="post-metadata">

### Author: ![s.moran](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@s.moran](https://discuss.elastic.co/u/s.moran)
#### Post date: [October 10, 2023, 8:32pm UTC](https://discuss.elastic.co/t/scripted-update-fails-with-unsupport-operation-exception-null/344349/2 "2023-10-10T20:32:29Z")

</div>

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

```auto
try {
  ctx._source.groups.social = social;
} catch (Exception e) {
  Debug.explain(ctx._source.groups);
}

```

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 7, 2023, 8:33pm UTC](https://discuss.elastic.co/t/scripted-update-fails-with-unsupport-operation-exception-null/344349/3 "2023-11-07T20:33:01Z")

</div>

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