# Total Hours bar chart from min starttime and max endtime. How?

**URL:** <https://discuss.elastic.co/t/total-hours-bar-chart-from-min-starttime-and-max-endtime-how/135325>\
**Category:** Kibana\
**Created:** [June 11, 2018, 9:46am UTC](https://discuss.elastic.co/t/total-hours-bar-chart-from-min-starttime-and-max-endtime-how/135325 "2018-06-11T09:46:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Sankarankutt](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@Sandeep\_Sankarankutt](https://discuss.elastic.co/u/Sandeep_Sankarankutt)\
**Post date:** [June 11, 2018, 9:46am UTC](https://discuss.elastic.co/t/total-hours-bar-chart-from-min-starttime-and-max-endtime-how/135325/1 "2018-06-11T09:46:35Z")

</div>

I am trying to create a visualization by considering a min of a start time and max of end time in a day logged by 1000's of documents based on a unique id. How can i perform this in Kibana ? Will scripted field help me here ?

for example  
Total Hours: 2 hours is calculated from Doc1 and Doc2 with uniqueid : unique1  
Doc 1  
{  
"runid" : "Unique1",  
"starttime" : "2018-06-10 T 00:00:15"  
"endtime" : "2018-06-10 T 00:48:15"  
}

Doc2

{  
"runid" : "Unique1",  
"starttime" : "2018-06-10 T 00:50:15"  
"endtime" : "2018-06-10 T 02:00:15"  
}

Total Hours: 45mins is calculated from Doc3 and Doc4 with uniqueid : unique2  
Doc 3  
{  
"runid" : "Unique2",  
"starttime" : "2018-06-10 T 00:00:20"  
"endtime" : "2018-06-10 T 00:26:15"  
}

Doc4  
{  
"runid" : "Unique2",  
"starttime" : "2018-06-10 T 00:27:15"  
"endtime" : "2018-06-10 T 00:45:20"  
}

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 12, 2018, 7:30am UTC](https://discuss.elastic.co/t/total-hours-bar-chart-from-min-starttime-and-max-endtime-how/135325/2 "2018-06-12T07:30:27Z")

</div>

Hi Sandeep,

this is unfortunately not possible with scripted fields, since scripted fields can only be used to calculate a value within one document. In you case you actually need to look across multiple documents to come up with the result.

I think the only way to calculate this would be a [scripted fields aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html), where you basically have a terms aggregation for the `runid` on the outer level and then nest a scripted fields, that keeps on reducing the min/max value of all fields, and in the end (`reduce_script`) actually calculate the difference between those two absolute min/max within that bucket.

Scripted metrics field are not yet supported in Kibana, you can track [#2646](https://github.com/elastic/kibana/issues/2646) to stay informed about scripted metrics field aggregation.

Cheers,  
Tim

---

<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:** [July 10, 2018, 7:30am UTC](https://discuss.elastic.co/t/total-hours-bar-chart-from-min-starttime-and-max-endtime-how/135325/3 "2018-07-10T07:30:40Z")

</div>

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