# Converting Unique field names into values in key/value style

**URL:** <https://discuss.elastic.co/t/converting-unique-field-names-into-values-in-key-value-style/92958>\
**Category:** Logstash\
**Created:** [July 13, 2017, 8:07am UTC](https://discuss.elastic.co/t/converting-unique-field-names-into-values-in-key-value-style/92958 "2017-07-13T08:07:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonasbareiss](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jonasbareiss](https://discuss.elastic.co/u/jonasbareiss)\
**Post date:** [July 13, 2017, 8:07am UTC](https://discuss.elastic.co/t/converting-unique-field-names-into-values-in-key-value-style/92958/1 "2017-07-13T08:07:37Z")

</div>

Hello everyone,  
I Have documents with hundreds of fields with unique field names.  
To avoid a huge mapping, I would like to convert them to the key/value style.

So out of something like

```auto
"deviceType" : "rfid",
"attempts": 1
```

i want to get something like

```auto
"properties" : [
{ "key" : "deviceType", "valueKeyword": "rfid" },
{ "key" : "attempts", "valueInteger": 1 },
]
```

Is this possible with logstash?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 13, 2017, 9:12am UTC](https://discuss.elastic.co/t/converting-unique-field-names-into-values-in-key-value-style/92958/2 "2017-07-13T09:12:34Z")

</div>

It's possible to do with a ruby filter. Something like

```ruby
event.to_hash.each { |k, v|
  event.get('properties') << {'key' => k, 'valueKeyword' => v}
}

```

should work. It assumes that `properties` exists as an array field and that all values are strings so it'll take some adjustments.

---

<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:** [August 10, 2017, 9:12am UTC](https://discuss.elastic.co/t/converting-unique-field-names-into-values-in-key-value-style/92958/3 "2017-08-10T09:12:46Z")

</div>

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