In my index i have field called build duration with 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 ("build_duration" => "6409651") need help to convert into HH:mm:ss format. Have tried the below
but it is not working. So can someone help me to work this? Any help would be highly appreciated.
Script:
String millisecondsString = doc['build_duration.keyword'].value;
long milliseconds = 1000000;
long minutes = (milliseconds / 1000) / 60;
long seconds = (milliseconds / 1000) % 60;
ZoneId z = ZoneId.of("Z");
Instant instant = Instant.ofEpochMilli(milliseconds);
LocalDateTime l = LocalDateTime.ofInstant(instant, z);
return l;
preview result
[
{
"_id": "37361323",
"build_duration": "1062735",
"test": [
"1970-01-01T00:16:40.000Z"
]
},
{
"_id": "37200499",
"build_duration": "1446172",
"test": [
"1970-01-01T00:16:40.000Z"
]
},
Kibana Discover field result.


instantdefined? Seems we're missing something here - Val"build_duration" => "6409651"- Kishoreinstantcome from here:LocalDateTime.ofInstant(instant, z);? - ValInstant instant = Instant.ofEpochMilli(milliSinceEpoch);- KishoremilliSinceEpochdefined? - Val