# Create a new field with ruby filter

**URL:** <https://discuss.elastic.co/t/create-a-new-field-with-ruby-filter/166307>\
**Category:** Logstash\
**Created:** [January 30, 2019, 8:50am UTC](https://discuss.elastic.co/t/create-a-new-field-with-ruby-filter/166307 "2019-01-30T08:50:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thelfter](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@thelfter](https://discuss.elastic.co/u/thelfter)\
**Post date:** [January 30, 2019, 8:50am UTC](https://discuss.elastic.co/t/create-a-new-field-with-ruby-filter/166307/1 "2019-01-30T08:50:45Z")

</div>

```
grok { match => { "request" => ["url", "%{URIPATH:url_path}%{URIPARAM:url_params}?"]} }
  urldecode{ field => "url_path" }
  mutate { gsub => ["url_params","\?",""] }
  kv {
    field_split => "&"
    source => "url_params"
    target => "params"
  }
  urldecode{ field => "params" }
  
  ruby {
    code => 'pattern= params.keys.join(",")'
    #Pattern should be the new field that contains the key, separated by comma
  }

```

So here the params is a hash, and I would like to concat all of the keys and store it to a new field, how can I achieve that?

---

<div class="post-metadata">

**Author:** ![danhermann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danhermann/32/33024_2.png) [@danhermann](https://discuss.elastic.co/u/danhermann)\
**Post date:** [January 30, 2019, 11:00am UTC](https://discuss.elastic.co/t/create-a-new-field-with-ruby-filter/166307/2 "2019-01-30T11:00:43Z")

</div>

@thelfter, you can use `event.set('field_name', field_value)` within a Ruby filter to create a new field and set its value.

---

<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:** [February 27, 2019, 11:00am UTC](https://discuss.elastic.co/t/create-a-new-field-with-ruby-filter/166307/3 "2019-02-27T11:00:44Z")

</div>

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