# Reindex data with a new Field

**URL:** https://discuss.elastic.co/t/reindex-data-with-a-new-field/115073
**Category:** Elasticsearch
**Created:** [January 11, 2018, 11:42am UTC](https://discuss.elastic.co/t/reindex-data-with-a-new-field/115073 "2018-01-11T11:42:38Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [January 19, 2018, 3:43pm UTC](https://discuss.elastic.co/t/reindex-data-with-a-new-field/115073/2 "2018-01-19T15:43:48Z")

</div>

There is an example of using reindex to modify the document in the docs [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-change-name). It changes the name of a field but you can use the same `script` construct to do what you want to do. I suspect the script looks something like `"script": "ctx._source['timestamp_hour'] = ctx._source['@timestamp'].getHourOfDay()`. You are right that it will be much better at search time to use this new field. Watch the time zone, btw. I believe the hour that you get in this case is UTC.

You could also do this with `_update_by_query` because it just introduces a new field which is a change you can do on an existing index. You'll end up with deleted documents in your index but merge should remove them in time. Not all of them, but a bunch. That might be easier to deal with depending on what you are doing.

---

_[View the full topic](https://discuss.elastic.co/t/reindex-data-with-a-new-field/115073)._
