# Generating metrics from documents present in index

**URL:** <https://discuss.elastic.co/t/generating-metrics-from-documents-present-in-index/318130>\
**Category:** Elasticsearch\
**Created:** [November 3, 2022, 6:22pm UTC](https://discuss.elastic.co/t/generating-metrics-from-documents-present-in-index/318130 "2022-11-03T18:22:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikash\_Kumar\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikash_kumar_sharma/32/112912_2.png) [@Vikash\_Kumar\_Sharma](https://discuss.elastic.co/u/Vikash_Kumar_Sharma)\
**Post date:** [November 3, 2022, 6:22pm UTC](https://discuss.elastic.co/t/generating-metrics-from-documents-present-in-index/318130/1 "2022-11-03T18:22:24Z")

</div>

Hi

I have an index that has the following documents

```auto
timestamp:t1, job:j1, status:started
timestamp:t2, job:j1, status:completed
timestamp:t1, job:j2, status:started
timestamp:t2, job:j2, status:completed

```

So from these record I want to generate metrics like given range of last 10 days with window as day, what was the average, min, max time taken by jobs to get completed

This requires a date histogram aggregation but since I don't have a duration filed in my document onto which I cannot apply the min,max,average aggregation, also here the duration will be for job j1, timestamp:t2 - timestamp:t1 which comes from two docs.

I am inserted records into Elasticsearch by listening onto a DynamoDB Stream, and basically inserted the updated version of record as a new entry in Elasticsearch.

Any help on how I can achieve this?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 15, 2022, 6:14am UTC](https://discuss.elastic.co/t/generating-metrics-from-documents-present-in-index/318130/2 "2022-11-15T06:14:32Z")

</div>

Welcome to our community! 😃

You need to add a new field here that calculates the duration, you could do that with a runtime field for eg. Then you could calculate things off that.

---

<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:** [December 13, 2022, 6:14am UTC](https://discuss.elastic.co/t/generating-metrics-from-documents-present-in-index/318130/3 "2022-12-13T06:14:39Z")

</div>

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