# Ruby Map Counter not working fine

**URL:** <https://discuss.elastic.co/t/ruby-map-counter-not-working-fine/106801>\
**Category:** Logstash\
**Created:** [November 8, 2017, 5:35am UTC](https://discuss.elastic.co/t/ruby-map-counter-not-working-fine/106801 "2017-11-08T05:35:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MariumHassan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mariumhassan/32/30321_2.png) [@MariumHassan](https://discuss.elastic.co/u/MariumHassan)\
**Post date:** [November 8, 2017, 5:35am UTC](https://discuss.elastic.co/t/ruby-map-counter-not-working-fine/106801/1 "2017-11-08T05:35:19Z")

</div>

Hi all,  
I have the following piece of code where I am just using an orderCounter to count the orders but I end up getting wrong count in my FILE\_SAVED logs. I have checked my log file. There isn't any issue in it, and all the groks are working fine as I am getting the right status field against my logs which I add in my groks.  
Please let me know if I am doing anything wrong.

```auto
  if [status] == "FILE_CREATED"
  {
    ruby
    {
      init => "@@map = {}"
      code => "@@map['orderCounter'] = 0;"
    }
  } 
  else if [status] == "ORDER_SAVED"
  {
      ruby
      {
        code => "@@map['orderCounter']+=1;"
      } 
  }
  else if [status] == "FILE_SAVED"
  {
    ruby
    {
      code => "event.set('orderCount', @@map['orderCounter']);" 
    }
  }
```

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [November 8, 2017, 12:06pm UTC](https://discuss.elastic.co/t/ruby-map-counter-not-working-fine/106801/2 "2017-11-08T12:06:10Z")

</div>

It might be some thread concurrency issue, try running it with 1 worker and see if the counter matches the documents.

---

<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 6, 2017, 12:06pm UTC](https://discuss.elastic.co/t/ruby-map-counter-not-working-fine/106801/3 "2017-12-06T12:06:12Z")

</div>

Closed on December 6, 2017, 12:06pm UTC

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