# How to perform operations with different fields on multiple records

**URL:** <https://discuss.elastic.co/t/how-to-perform-operations-with-different-fields-on-multiple-records/174248>\
**Category:** Kibana\
**Created:** [March 28, 2019, 6:32am UTC](https://discuss.elastic.co/t/how-to-perform-operations-with-different-fields-on-multiple-records/174248 "2019-03-28T06:32:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason1992](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@jason1992](https://discuss.elastic.co/u/jason1992)\
**Post date:** [March 28, 2019, 6:32am UTC](https://discuss.elastic.co/t/how-to-perform-operations-with-different-fields-on-multiple-records/174248/1 "2019-03-28T06:32:22Z")

</div>

Hi, I am dealing with Json data which contain a key value.  
2 different records will have the same key value (both get ingested at a different time) with one of them having a field "startTime" and the other having a field "endTime".

Is it possible to visualize this data by grouping based on the key and calculating the time difference between these 2 fields (startTime and endTime)? Perhaps like a Data table showing the key and time taken as 2 columns. If this is possible, can you please provide few pointers?

Thank you and any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![christophilus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christophilus/32/42991_2.png) [@christophilus](https://discuss.elastic.co/u/christophilus)\
**Post date:** [March 28, 2019, 3:55pm UTC](https://discuss.elastic.co/t/how-to-perform-operations-with-different-fields-on-multiple-records/174248/2 "2019-03-28T15:55:08Z")

</div>

I think this can be done with a scripted metric aggregation:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html)

Basically, you'd want to select the non-null startdate and enddate in two different scripted metrics.

---

<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:** [April 25, 2019, 3:55pm UTC](https://discuss.elastic.co/t/how-to-perform-operations-with-different-fields-on-multiple-records/174248/3 "2019-04-25T15:55:11Z")

</div>

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