# How to compare 2 numerical field values with each other?

**URL:** <https://discuss.elastic.co/t/how-to-compare-2-numerical-field-values-with-each-other/188840>\
**Category:** Logstash\
**Created:** [July 4, 2019, 6:22am UTC](https://discuss.elastic.co/t/how-to-compare-2-numerical-field-values-with-each-other/188840 "2019-07-04T06:22:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [July 4, 2019, 6:22am UTC](https://discuss.elastic.co/t/how-to-compare-2-numerical-field-values-with-each-other/188840/1 "2019-07-04T06:22:40Z")

</div>

Hi,

Is it possible to load the value of a field and use that to compare it to another field and based on that add a new field with a value?

E.g.

```
if [temperature] > [alert1] 
  add field "outcome => normal"
if else [temperature] > [alert2]
   add field "outcome => high"

```

Something like the below will work but it will be a lot of work to maintain as I have many different alert values. The above should be more flexible as I'd only need one line for each alert.

```
if [alert1] == "1000" and temperature >1000 
 add field "outcome => normal"
```

---

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [July 4, 2019, 8:07am UTC](https://discuss.elastic.co/t/how-to-compare-2-numerical-field-values-with-each-other/188840/2 "2019-07-04T08:07:43Z")

</div>

To anwser my own question and in case anyone is every looking to do something similar, I got it working using this piece if ruby.

```
 ruby {
           code => "
             if event.get('temperature').to_i >= event.get('alert1').to_i
               event.set('outcome', 'normal');
             end
           "
         }
```

---

<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:** [August 1, 2019, 8:08am UTC](https://discuss.elastic.co/t/how-to-compare-2-numerical-field-values-with-each-other/188840/3 "2019-08-01T08:08:02Z")

</div>

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