Incrementing Datetime field by one day in Elasticsearch Production Cluster using painless script

I am facing difficulty in debugging a production level Elasticsearch Index Date time field in yyyy-MM-dd format & i want to update/increment the datetime field by one day Eg- 2009-07-01 i want to update it to 2009-07-02 for all the documents in the index without time.

I also want to know whether i have to use the re index api or update by query api

Currently i tried to update the document using following painless script its not working

POST klaprod-11042022/_update_by_query


{
  "script": {
    "source": "def df = DateTimeFormatter.ofPattern('yyyy-MM-dd');def tmp = LocalDateTime.parse(ctx._source.debate_section_date,df);ctx._source.debate_section_date=tmp.plusDays(1);",
    "lang": "painless"
  },
  "query": {"match_all":{}}
}

Kindly Advise

Hey,

so the update-by-query API is doing in-place updates, so that sounds like a good way to go.

Second, can you be more specific with your requirement? You first wanted to run this for all documents that don't have a field set, however in your script you are indeed accessing an existing field? If the first, then you could change the match_all query to run less updates in total.

Can you also share a sample document in your index and the error message instead of just saying it's not working so that debugging is easier?

Thank you!

--Alex

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