I am creating index every day for some computation i am running , turns out i forgot to add a timestamp field to the index.
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": {}
}
}