Generating metrics from documents present in index

Hi

I have an index that has the following documents

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?

Welcome to our community! :smiley:

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.