# How to do calculations in Logstash

**URL:** <https://discuss.elastic.co/t/how-to-do-calculations-in-logstash/319759>\
**Category:** Logstash\
**Created:** [November 24, 2022, 1:23pm UTC](https://discuss.elastic.co/t/how-to-do-calculations-in-logstash/319759 "2022-11-24T13:23:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakhshunda\_Noorein\_J](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rakhshunda_noorein_j/32/99407_2.png) [@Rakhshunda\_Noorein\_J](https://discuss.elastic.co/u/Rakhshunda_Noorein_J)\
**Post date:** [November 24, 2022, 1:23pm UTC](https://discuss.elastic.co/t/how-to-do-calculations-in-logstash/319759/1 "2022-11-24T13:23:30Z")

</div>

Hello,  
Please find my configuration file structure

```auto
input{
http_poller{
// here I have mentioned API url and authorisation
tags => ["tag1"]
}
http_poller{
// here I have mentioned API url and authorisation
tags => ["tag2"]
}
http_poller{
// here I have mentioned API url and authorisation
tags => ["tag3"]
}
}
filter { 
  mutate {
	remove_field => ["[message]" ]
	remove_field => ["[@version]" ]
	remove_field => ["[@timestamp]" ]
	remove_field => ["[event]" ]
  }

// I want to do calculations here... As for example for every http_poller I want to do like this..
if "tag1" in tags
{
find max(elements) in tag1
find min(element) in tag1
add_field=> calculatedfield = max - min/max;
}
if "tag2" in tags
{
find max(elements) in tag2
find min(element) in tag2
add_field=> calculatedfield = max - min/max;
}
if "tag3" in tags
{
find max(elements) in tag3
find min(element) in tag3
add_field=> calculatedfield = max - min/max;
}

}
output{
if "tag1" in tags
{
elasticsearch{
//elastic credentials and index name
}
}
if "tag2" in tags
{
elasticsearch{
//elastic credentials and index name
}
}
if "tag3" in tags
{
elasticsearch{
//elastic credentials and index name
}
}
}

```

I want to calculate the max and min of a field for every api in http\_poller and add a field.  
Please help me in this...

---

<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 22, 2022, 1:23pm UTC](https://discuss.elastic.co/t/how-to-do-calculations-in-logstash/319759/2 "2022-12-22T13:23:55Z")

</div>

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