# Reindex data with with new timestamp field

**URL:** https://discuss.elastic.co/t/reindex-data-with-with-new-timestamp-field/161961
**Category:** Elasticsearch
**Created:** [December 24, 2018, 12:03am UTC](https://discuss.elastic.co/t/reindex-data-with-with-new-timestamp-field/161961 "2018-12-24T00:03:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Roman\_Kournjaev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman_kournjaev/32/2552_2.png) [@Roman\_Kournjaev](https://discuss.elastic.co/u/Roman_Kournjaev)
#### Post date: [December 24, 2018, 12:03am UTC](https://discuss.elastic.co/t/reindex-data-with-with-new-timestamp-field/161961/1 "2018-12-24T00:03:14Z")

</div>

I am creating index every day for some computation i am running , turns out i forgot to add a timestamp field to the index.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b2f7fd6dd63f45a654dc8303cce3ef33b2ebd99d.png)

I would like to reindex every index into a new one and add a @timestamp field that is extracted from the index name.

I am struggling to find the right syntax in the painless script todo so.

I guess it should be something like that :

POST \_reindex  
{  
"source": {  
"index": "amazon-pd-2018-12-18-days-back-1"  
},  
"dest": {  
"index": "amazon-pd-2018-12-18-days-back-1-new"  
},  
"script": {  
"inline": "def inputFormat = new SimpleDateFormat('yyyy-MM-dd');def myDate = inputFormat.parse('2018-12-18');ctx.\_dest['@timestamp'] = myDate"  
}  
}

Ok update that did the trick

```
POST amazon-pd-2018-12-24-days-back-1/_update_by_query

```

{  
"script": {  
"source": "def inputFormat = new SimpleDateFormat('yyyy-MM-dd');def myDate = inputFormat.parse('2018-12-24');ctx.\_source['@timestamp'] = myDate",  
"lang": "painless"  
},  
"query": {  
"match\_all": {}  
}  
}

---

<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: [January 21, 2019, 12:03am UTC](https://discuss.elastic.co/t/reindex-data-with-with-new-timestamp-field/161961/2 "2019-01-21T00:03:18Z")

</div>

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