# How to update a filed with current date and time in ES5.6?

**URL:** <https://discuss.elastic.co/t/how-to-update-a-filed-with-current-date-and-time-in-es5-6/102532>\
**Category:** Elasticsearch\
**Created:** [October 3, 2017, 8:56am UTC](https://discuss.elastic.co/t/how-to-update-a-filed-with-current-date-and-time-in-es5-6/102532 "2017-10-03T08:56:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)\
**Post date:** [October 3, 2017, 9:32am UTC](https://discuss.elastic.co/t/how-to-update-a-filed-with-current-date-and-time-in-es5-6/102532/2 "2017-10-03T09:32:52Z")

</div>

Rather than using the fairly slow update query just to modify one field why not use a [pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/pipeline.html) to set the processing time as the document gets indexed (or updated). Something like

```
{
    "description" : "Pipeline for setting the document processing time",
    "processors" : [
      {
        "script" : {
          "lang" : "painless",
          "inline" : "DateFormat df = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\");\ndf.setTimeZone(TimeZone.getTimeZone(\"UTC\"));\nDate date = new Date();\nctx.proctime = df.format(date);"
        }
      }
    ]
}

```

Here the field "proctime" is created and set to the current time for each document indexed through this pipeline processor. All you need is to pass along the pipeline=\<my\_named\_pipe\> parameter when indexing documents.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-update-a-filed-with-current-date-and-time-in-es5-6/102532)._
