How to convert miliseconds into hh:mm:ss using plainless

With ELK - 7.10.1 i am trying to visualize kibana using painless script, Currently i have logstash output data in the below format.

"build_end_time" => "2021-01-13 01:29:49",
"build_duration" => "6409651",
"build_start_time" => "2021-01-12 23:43:00",
"build_date" => "2021-01-12",
"@timestamp" => 2021-02-02T11:40:50.747Z,

Here build_duration i have in milliseconds. how do i covert into hh:mm:ss? Below is my painless script settings.

   String milliSinceEpochString = doc['build_duration'].value;
long milliSinceEpoch = Long.parseLong(milliSinceEpochString);
Instant instant = Instant.ofEpochMilli(milliSinceEpoch);
ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.of('Z'));
return zdt

The above code is not working, basically i need to create daily average build duration visualization with the script field. Can someone help me to achieve the same?

This does not feel like a logstash question. Either you are asking about a presentation issue in kibana, or you are asking about a scripting issue when indexing (which would make it an elasticsearch question).

Ok i will move to elasticsearch category.

In my index already i have field called build duration but it is in string type, Since i want to visualize the average of build_duration In Line chart Y-axis i want to select Average but if i select it shows The index pattern build-info does not contain any of the following compatible field types: number or histogram So for this reason i am looking to create scripted field to calculate the build duration average. currently it is in milliseconds need help to convert into HH:mm:ss format, Any help would be highly appreciated.

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