# Bucket aggregation - calculate my own metric inside bucket

**URL:** https://discuss.elastic.co/t/bucket-aggregation-calculate-my-own-metric-inside-bucket/291326
**Category:** Elasticsearch
**Created:** [December 9, 2021, 12:42pm UTC](https://discuss.elastic.co/t/bucket-aggregation-calculate-my-own-metric-inside-bucket/291326 "2021-12-09T12:42:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Detlic\_Detlicko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/detlic_detlicko/32/98621_2.png) [@Detlic\_Detlicko](https://discuss.elastic.co/u/Detlic_Detlicko)
#### Post date: [December 9, 2021, 12:42pm UTC](https://discuss.elastic.co/t/bucket-aggregation-calculate-my-own-metric-inside-bucket/291326/1 "2021-12-09T12:42:42Z")

</div>

Hello,  
i collect data from my router and store into Elasticsearch.

My data mappings are in this form : \< {"interface\_name":"keyword", "value":"double", "timestamp":"integer"}. \>

I need to measure flow for each interface like: \< flow = (v2-v1)/(t2-t1) \>.

So if i have for an example two interfaces with same name  
(interface:"i1" value: 5 ts: 2) and (interface: "i1" value:10 ts:3 ) i need to get (10-5)/(3-2) as output.

I group each interface into bucket with bucket aggregation and i know how to get avg/max/min, but i don't know how to calculate with my own formula.

This is my first post on forum,  
Thank you in advance!

---

<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: [January 6, 2022, 12:43pm UTC](https://discuss.elastic.co/t/bucket-aggregation-calculate-my-own-metric-inside-bucket/291326/2 "2022-01-06T12:43:26Z")

</div>

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