# Logstash 5.0 Ruby Filter Can't Update Hash in Array

**URL:** https://discuss.elastic.co/t/logstash-5-0-ruby-filter-cant-update-hash-in-array/90647
**Category:** Logstash
**Created:** [June 23, 2017, 2:00pm UTC](https://discuss.elastic.co/t/logstash-5-0-ruby-filter-cant-update-hash-in-array/90647 "2017-06-23T14:00:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Java\_Beta](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@Java\_Beta](https://discuss.elastic.co/u/Java_Beta)
#### Post date: [June 23, 2017, 2:00pm UTC](https://discuss.elastic.co/t/logstash-5-0-ruby-filter-cant-update-hash-in-array/90647/1 "2017-06-23T14:00:10Z")

</div>

I'm a newbie to Logstash and Ruby, and I meet a subtle problem today.

My input JSON like the following:

```
{
  "1": "1",
  "2": "2",
  "market": [
    {
      "id": "1",
      "name": "m1"
    },
    {
      "id": "2",
      "name": "m2"
    }
  ]
}

```

My filter is:

```
filter {
    ......
    ruby {
        code => "
        markets = event.get('market')
        markets.each_index do |index| 
    event.set(markets[index]['id'], markets[index]['name']) 
    markets[index]['id'] = markets[index]['name']
    end
"
}
......
}

```

And the output is:

```
{
  "1": "m1",
  "2": "m2",
  "market": [
    {
      "id": "1",
      "name": "m1"
    },
    {
      "id": "2",
      "name": "m2"
    }
  ]
}

```

What I expect to be:

```
{
  "1": "m1",
  "2": "m2",
  "market": [
    {
      "id": "m1",
      "name": "m1"
    },
    {
      "id": "m2",
      "name": "m2"
    }
  ]
}

```

I think [market.id](http://market.id) should be m1 not 1, could anyone give me some clue what's wrong with my filter?  
The logstash I'm using is version 5.0.

---

<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 21, 2017, 2:00pm UTC](https://discuss.elastic.co/t/logstash-5-0-ruby-filter-cant-update-hash-in-array/90647/2 "2017-07-21T14:00:28Z")

</div>

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