# How can I create a new term by subtracting to other terms?

**URL:** <https://discuss.elastic.co/t/how-can-i-create-a-new-term-by-subtracting-to-other-terms/99401>\
**Category:** Logstash\
**Created:** [September 5, 2017, 10:28am UTC](https://discuss.elastic.co/t/how-can-i-create-a-new-term-by-subtracting-to-other-terms/99401 "2017-09-05T10:28:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [September 5, 2017, 10:28am UTC](https://discuss.elastic.co/t/how-can-i-create-a-new-term-by-subtracting-to-other-terms/99401/1 "2017-09-05T10:28:21Z")

</div>

Hi,

I have 2 terms X and Y. How can I create a third term Z that is X-Y in my logs through logstash?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 7, 2017, 5:31am UTC](https://discuss.elastic.co/t/how-can-i-create-a-new-term-by-subtracting-to-other-terms/99401/2 "2017-09-07T05:31:47Z")

</div>

Use a ruby filter with the following code:

```
event.set('Z', event.get('X') - event.get('Y'))

```

This assumes that the `X` and `Y` fields are numeric.

---

<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:** [October 5, 2017, 5:32am UTC](https://discuss.elastic.co/t/how-can-i-create-a-new-term-by-subtracting-to-other-terms/99401/3 "2017-10-05T05:32:19Z")

</div>

Closed on October 5, 2017, 5:32am UTC

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