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

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):


  "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

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