# Update all fields containing specific string in field name by painless script

**URL:** https://discuss.elastic.co/t/update-all-fields-containing-specific-string-in-field-name-by-painless-script/275973
**Category:** Elasticsearch
**Tags:** painless
**Created:** [June 15, 2021, 9:55am UTC](https://discuss.elastic.co/t/update-all-fields-containing-specific-string-in-field-name-by-painless-script/275973 "2021-06-15T09:55:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sbienert](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sbienert](https://discuss.elastic.co/u/sbienert)
#### Post date: [June 15, 2021, 9:55am UTC](https://discuss.elastic.co/t/update-all-fields-containing-specific-string-in-field-name-by-painless-script/275973/1 "2021-06-15T09:55:06Z")

</div>

Hi, I have a pretty simple request but I don't manage to get it working. I need to increase a datetime of multiple fields in one document. The date fields can be nested fields at different levels. Instead of having to update every single field specifically I wanted to update all fields containing "Date" in the field name. I tried it like this (with \_update\_by\_query):

```auto
{

  "script": {

    "source": "def df = DateTimeFormatter.ISO_OFFSET_DATE_TIME; Iterator it = ctx.entrySet().iterator(); while (it.hasNext()) { if (it.next().getKey().contains(\"Date\") && it.next().getValue() != null) { def tmp = OffsetDateTime.parse(it.next().getValue(),df); it.next().getValue()=tmp.plusDays(1);}}",

    "lang": "painless"

  }

}

```

But it does not work (giving error message "Left-hand side cannot be assigned a value."). Can anyone tell me how it could work or if it even yould work?

Thanks in advance

---

<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: [July 13, 2021, 9:55am UTC](https://discuss.elastic.co/t/update-all-fields-containing-specific-string-in-field-name-by-painless-script/275973/2 "2021-07-13T09:55:13Z")

</div>

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