# Elasticsearch Watcher - convert the milliseconds-since-the-epoch value back into a string

**URL:** <https://discuss.elastic.co/t/elasticsearch-watcher-convert-the-milliseconds-since-the-epoch-value-back-into-a-string/154000>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 25, 2018, 12:33pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-convert-the-milliseconds-since-the-epoch-value-back-into-a-string/154000 "2018-10-25T12:33:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathir\_J](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@Kathir\_J](https://discuss.elastic.co/u/Kathir_J)\
**Post date:** [October 25, 2018, 12:33pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-convert-the-milliseconds-since-the-epoch-value-back-into-a-string/154000/1 "2018-10-25T12:33:03Z")

</div>

Hi,

I am currently trying with watcher for anomalies.  
Here is my text field which gets notified in slack.

"text": "Machine Learning Results - Object cache size is going to exceed threshold limit.\n Anomalies:\n{{#ctx.payload.hits.hits}}score={{\_source.anomaly\_score}} at time={{\_source.timestamp}}\n{{/ctx.payload.hits.hits}}"

and in slack, it is notified as below.

Machine Learning Results - Object cache size is going to exceed threshold limit.  
Anomalies:  
score=34.23307635237295 at time=1540379400000  
score=32.13437 at time=1540379700000

\_source.timestamp is producing milliseconds-since-the-epoch value. But I would like to notify this value as readable date format.

Is there way to format this ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 25, 2018, 12:57pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-convert-the-milliseconds-since-the-epoch-value-back-into-a-string/154000/2 "2018-10-25T12:57:07Z")

</div>

Hey,

you need to do a [script transform](https://www.elastic.co/guide/en/elastic-stack-overview/6.4/transform-script.html) first to convert the time to an Instant using `Instant.ofEpochMilli()` and then use java-time methods.

Also be aware, that a transform replaces the existing payload, so you have to make sure you return the full payload and enrich the date fields.

Hope this helps!

--Alex

---

<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:** [November 22, 2018, 12:59pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-convert-the-milliseconds-since-the-epoch-value-back-into-a-string/154000/3 "2018-11-22T12:59:35Z")

</div>

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