# Can't add a new key into hash during iteration

**URL:** <https://discuss.elastic.co/t/cant-add-a-new-key-into-hash-during-iteration/2678>\
**Category:** Logstash\
**Created:** [June 15, 2015, 9:04am UTC](https://discuss.elastic.co/t/cant-add-a-new-key-into-hash-during-iteration/2678 "2015-06-15T09:04:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saket\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Saket\_Kumar](https://discuss.elastic.co/u/Saket_Kumar)\
**Post date:** [June 15, 2015, 9:04am UTC](https://discuss.elastic.co/t/cant-add-a-new-key-into-hash-during-iteration/2678/1 "2015-06-15T09:04:40Z")

</div>

Getting exception while executing below ruby block:  
ruby {  
code =\> "  
event.to\_hash.each\_pair do |k, v|  
if k == 'Time\_FV'  
event['TimeFV']= event[k]  
elsif k== 'Progess\_FV'  
event['ProgessFV']= event[k]  
elsif k== 'Time\_RV'  
event['TimeRV']= event[k]  
elsif k== 'Progess\_RV'  
event['ProgessRV']= event[k]  
end  
end  
"   
}

getting error:

Exception in filterworker {"exception"=\>#\<RuntimeError: can't add a new key into hash during iteration\>, "backtrace"=\>["org/jruby/RubyHash.java:991:in `[]='", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.0-java/lib/logstash/util/accessors.rb:42:in`set'", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.0-java/lib/logstash/event.rb:146:in `[]='", "(ruby filter code):4:in`register'", "org/jruby/RubyHash.java:1366:in `each_pair'", "(ruby filter code):2:in`register'", "org/jruby/RubyProc.java:271:in `call'", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-filter-ruby-0.1.5/lib/logstash/filters/ruby.rb:37:in`filter'", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.0-java/lib/logstash/filters/base.rb:162:in `multi_filter'", "org/jruby/RubyArray.java:1613:in`each'", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.0-java/lib/logstash/filters/base.rb:159:in `multi_filter'", "(eval):436:in`filter\_func'", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.0-java/lib/logstash/pipeline.rb:219:in `filterworker'", "/opt/Log/logstash-1.5.0/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.0-java/lib/logstash/pipeline.rb:156:in`start\_filters'"], :level=\>:error}

Any idea about this run time expection?

---

<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:** [July 6, 2017, 5:37am UTC](https://discuss.elastic.co/t/cant-add-a-new-key-into-hash-during-iteration/2678/2 "2017-07-06T05:37:30Z")

</div>

Closed on July 6, 2017, 5:37am UTC


