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

**URL:** <https://discuss.elastic.co/t/incrementing-datetime-field-by-one-day-in-elasticsearch-production-cluster-using-painless-script/302088>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [April 11, 2022, 9:42am UTC](https://discuss.elastic.co/t/incrementing-datetime-field-by-one-day-in-elasticsearch-production-cluster-using-painless-script/302088 "2022-04-11T09:42:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaibhav\_sanil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vaibhav_sanil/32/85728_2.png) [@vaibhav\_sanil](https://discuss.elastic.co/u/vaibhav_sanil)\
**Post date:** [April 11, 2022, 9:42am UTC](https://discuss.elastic.co/t/incrementing-datetime-field-by-one-day-in-elasticsearch-production-cluster-using-painless-script/302088/1 "2022-04-11T09:42:18Z")

</div>

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

```auto
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

---

<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:** [April 11, 2022, 1:45pm UTC](https://discuss.elastic.co/t/incrementing-datetime-field-by-one-day-in-elasticsearch-production-cluster-using-painless-script/302088/2 "2022-04-11T13:45:43Z")

</div>

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

---

<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:** [May 9, 2022, 1:45pm UTC](https://discuss.elastic.co/t/incrementing-datetime-field-by-one-day-in-elasticsearch-production-cluster-using-painless-script/302088/3 "2022-05-09T13:45:50Z")

</div>

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