# Need to do a calculation in logstash

**URL:** https://discuss.elastic.co/t/need-to-do-a-calculation-in-logstash/211117
**Category:** Logstash
**Created:** [December 9, 2019, 1:21pm UTC](https://discuss.elastic.co/t/need-to-do-a-calculation-in-logstash/211117 "2019-12-09T13:21:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![namali](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@namali](https://discuss.elastic.co/u/namali)
#### Post date: [December 9, 2019, 1:21pm UTC](https://discuss.elastic.co/t/need-to-do-a-calculation-in-logstash/211117/1 "2019-12-09T13:21:40Z")

</div>

logstash input is elasticsearch and there is field called 'check' in input index.  
when ever read the documents in this index need to increment check by 1.

I used ruby filter for this.  
ruby{code =\> "event.set('check',[event.get('check\_')].to\_i + 1)"}

getting following error  
[2019-12-09T18:48:30,925][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `to\_i' for ["0"]:Array

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [December 9, 2019, 3:22pm UTC](https://discuss.elastic.co/t/need-to-do-a-calculation-in-logstash/211117/2 "2019-12-09T15:22:19Z")

</div>

Remove the square brackets around event.get('check\_'). They turn it into an array and prevent .to\_i working. Square brackets are used to reference fields in the logstash configuration, not in ruby.

---

<div class="post-metadata">

### Author: ![namali](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@namali](https://discuss.elastic.co/u/namali)
#### Post date: [December 10, 2019, 3:43am UTC](https://discuss.elastic.co/t/need-to-do-a-calculation-in-logstash/211117/3 "2019-12-10T03:43:25Z")

</div>

thx Badger, it got work.

---

<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 7, 2020, 3:43am UTC](https://discuss.elastic.co/t/need-to-do-a-calculation-in-logstash/211117/4 "2020-01-07T03:43:29Z")

</div>

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