# Painless scripting: Update a OBJECT FIELD

**URL:** <https://discuss.elastic.co/t/painless-scripting-update-a-object-field/195488>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [August 16, 2019, 12:01pm UTC](https://discuss.elastic.co/t/painless-scripting-update-a-object-field/195488 "2019-08-16T12:01:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koshur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/koshur/32/52434_2.png) [@Koshur](https://discuss.elastic.co/u/Koshur)\
**Post date:** [August 16, 2019, 12:01pm UTC](https://discuss.elastic.co/t/painless-scripting-update-a-object-field/195488/1 "2019-08-16T12:01:30Z")

</div>

We have a field called `access2` that is currently mapped with object (json).

Now I want to add some data to it based on some logic. I want to check the value of another field access (which is mapped to nested/array) and update the object accordingly.

E.g.  
Nested field - `"access": ["client": "yes"]`

I want the new `access2` field to contain data like -

`{"production": ["client": "yes"], "nonprod": ["client": "yes"]}`

I have tried below:

`POST json-index/_update_by_query { "script": { "source": """ ctx._source.access2 = { "production": ctx._source.access, "nonprod": ctx._source.access } """, "lang": "painless" } }`

But it is failing with below error:

> ```
> "lang": "painless",
> "caused_by": {
> "type": "illegal_argument_exception",
> "reason": "invalid sequence of tokens near ['{'].",
> "caused_by": {
> "type": "no_viable_alt_exception",
> "reason": null
> }
> }
> 
> ```
> 
> },  
> "status": 500

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 16, 2019, 12:43pm UTC](https://discuss.elastic.co/t/painless-scripting-update-a-object-field/195488/2 "2019-08-16T12:43:32Z")

</div>

hey,

please take the time to properly format your snippets. this is really hard to read and one could not copy & paste it into kibana.

I think the problem is the definition of your map using curly braces. Try

```auto
ctx._source.access2 = ["production": ctx._source.access, "nonprod": ctx._source.access]

```

--Alex

---

<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:** [September 13, 2019, 12:43pm UTC](https://discuss.elastic.co/t/painless-scripting-update-a-object-field/195488/3 "2019-09-13T12:43:34Z")

</div>

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