# Update index with static value instead of scripted field

**URL:** https://discuss.elastic.co/t/update-index-with-static-value-instead-of-scripted-field/263890
**Category:** Elasticsearch
**Created:** [February 10, 2021, 3:40pm UTC](https://discuss.elastic.co/t/update-index-with-static-value-instead-of-scripted-field/263890 "2021-02-10T15:40:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![stevezemlicka](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevezemlicka](https://discuss.elastic.co/u/stevezemlicka)
#### Post date: [February 10, 2021, 3:40pm UTC](https://discuss.elastic.co/t/update-index-with-static-value-instead-of-scripted-field/263890/1 "2021-02-10T15:40:51Z")

</div>

I have a scripted field generating the hour of the day in a particular index. Unfortunately due to the size and the necessary complexity (result of timezone challenges), it is making some Kibana visualizations slow.

Using a simple scripted field as follows works quickly but is inaccurate:

> return doc['@timestamp'].value.getHour();

The one I am using for accuracy is as follows:

> return LocalDateTime.ofInstant(Instant.ofEpochMilli(doc['@timestamp'].value.millis),ZoneId.of('America/Chicago')).getHour()

While I could modify the raw data and re-ingest, I would like to figure out how to do this with elasticsearch itself. Is it possible to run a post command to populate a new field like this? If so, how might i go about formulating a post/update like that?

---

<div class="post-metadata">

### Author: ![stevezemlicka](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevezemlicka](https://discuss.elastic.co/u/stevezemlicka)
#### Post date: [February 10, 2021, 4:43pm UTC](https://discuss.elastic.co/t/update-index-with-static-value-instead-of-scripted-field/263890/2 "2021-02-10T16:43:28Z")

</div>

or, maybe it would be more efficient to do a reindex of the dataset. Is it possible to include a scripted field's output in a reindex as a static value?

---

<div class="post-metadata">

### Author: ![stevezemlicka](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevezemlicka](https://discuss.elastic.co/u/stevezemlicka)
#### Post date: [February 10, 2021, 4:45pm UTC](https://discuss.elastic.co/t/update-index-with-static-value-instead-of-scripted-field/263890/3 "2021-02-10T16:45:49Z")

</div>

I might not have done enough research on this before posting...perhaps the answer is in something like:

> [@Reindex data with a new Field](https://discuss.elastic.co/t/reindex-data-with-a-new-field/115073):
>
> Hi, Is there anyway to reindex the data and create a new field, from the data in the documents. For example, reindex an entire index and create a new field Hour(number) from a date type field(YYYY-mm-dd, HH-mm-ss). I Know that Lucene has an expresion for this(doc['@timestamp'].date.getHourOfDay()), but can this be used to create a new field when you reindex? I need this new field for a search query and the scripted fields can't be used for this, the alternative is using a script on the query …

---

<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: [March 10, 2021, 4:46pm UTC](https://discuss.elastic.co/t/update-index-with-static-value-instead-of-scripted-field/263890/4 "2021-03-10T16:46:27Z")

</div>

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