# Painless script in Kibana to convert timestamp array in Date format

**URL:** <https://discuss.elastic.co/t/painless-script-in-kibana-to-convert-timestamp-array-in-date-format/121285>\
**Category:** Kibana\
**Created:** [February 23, 2018, 8:32pm UTC](https://discuss.elastic.co/t/painless-script-in-kibana-to-convert-timestamp-array-in-date-format/121285 "2018-02-23T20:32:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karanushah.1992](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@Karanushah.1992](https://discuss.elastic.co/u/Karanushah.1992)\
**Post date:** [February 23, 2018, 8:32pm UTC](https://discuss.elastic.co/t/painless-script-in-kibana-to-convert-timestamp-array-in-date-format/121285/1 "2018-02-23T20:32:49Z")

</div>

Hi, I have an array of of Epoch time in timestamp field. I want to use painless script to convert this array field in Date field which can be used by Kibana.

Following is my painless script

LocalDateTime date;  
for (int i = 0; i \< doc['timestamp'].length; ++i) {  
return  
date = LocalDateTime.ofInstant(Instant.ofEpochMilli(doc['timestamp'][i].value), ZoneId.of('Z')).getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())  
}

My Timestamp field looks like this  
"timestamp": [  
"1516402800000",  
"1516424400000",  
"1516446000000",  
]

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [February 23, 2018, 9:39pm UTC](https://discuss.elastic.co/t/painless-script-in-kibana-to-convert-timestamp-array-in-date-format/121285/2 "2018-02-23T21:39:27Z")

</div>

What is the mapping for the field? Why don't you store them as Dates in Elasticsearch?

[https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html)

[https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html)

---

<div class="post-metadata">

**Author:** ![Karanushah.1992](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@Karanushah.1992](https://discuss.elastic.co/u/Karanushah.1992)\
**Post date:** [February 25, 2018, 3:29pm UTC](https://discuss.elastic.co/t/painless-script-in-kibana-to-convert-timestamp-array-in-date-format/121285/3 "2018-02-25T15:29:19Z")

</div>

I have all the dates in an array and Date filter will not convert an array into Date.

---

<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 25, 2018, 3:29pm UTC](https://discuss.elastic.co/t/painless-script-in-kibana-to-convert-timestamp-array-in-date-format/121285/4 "2018-03-25T15:29:20Z")

</div>

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