# Logstash nested hashmap to top level

**URL:** <https://discuss.elastic.co/t/logstash-nested-hashmap-to-top-level/128346>\
**Category:** Logstash\
**Created:** [April 17, 2018, 12:18pm UTC](https://discuss.elastic.co/t/logstash-nested-hashmap-to-top-level/128346 "2018-04-17T12:18:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgprb](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@pgprb](https://discuss.elastic.co/u/pgprb)\
**Post date:** [April 17, 2018, 12:18pm UTC](https://discuss.elastic.co/t/logstash-nested-hashmap-to-top-level/128346/1 "2018-04-17T12:18:02Z")

</div>

Hi there,

So basically I have a very complex object (input is avro) that has nested lists, hashmaps and objects inside. Simplifying, something like this:

ObjectsA { #list of object A  
A1 {  
UUID;  
HashMap1 {  
Key: ObjectB1\_UUID;  
Value: Object B1 { B1\_UUI, B1\_Field\_1, ... B1\_Field\_N }  
};  
Field\_1 = ...  
...  
}  
A2 { ...}

and so on. The output desired, or at least the one that could help a lot to start, would be to have the nested maps (only them, not the value objects) and lists on top level, for instance:

A1.UUID;  
A1.HashMap1 { };  
A1.Field\_1;  
A2.UUID;  
...

If I split the ObjectsA list, what I have at the end is a lot of fields (this is a very complex object...) like A1.HashMap1.B1.UUID.Field\_1 to A1.HashMap1.B1.UUID.Field\_N, which is not what I would like to have. I also tried to apply ruby coding but with pretty similar results (and also I'm a newbie at ruby..).

Any help would be much appreciated.

Many thanks

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 17, 2018, 12:48pm UTC](https://discuss.elastic.co/t/logstash-nested-hashmap-to-top-level/128346/2 "2018-04-17T12:48:30Z")

</div>

Does this get you any closer to where you want to be?

```auto
  ruby {
    code => '
      event.set("ObjectsAFlattened", [])
      d = event.get("ObjectsA")
      d.each do |k1, v1|
        v1.each do |k2, v2|
          event.set("ObjectsAFlattened", event.get("ObjectsAFlattened").push("#{k1}-#{k2}"))
        end
      end
    '

```

---

<div class="post-metadata">

**Author:** ![pgprb](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@pgprb](https://discuss.elastic.co/u/pgprb)\
**Post date:** [April 17, 2018, 1:53pm UTC](https://discuss.elastic.co/t/logstash-nested-hashmap-to-top-level/128346/3 "2018-04-17T13:53:40Z")

</div>

Hi @Badger

Yes it helps a lot, I can work with this.

Thank you very much!

---

<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:** [May 15, 2018, 1:53pm UTC](https://discuss.elastic.co/t/logstash-nested-hashmap-to-top-level/128346/4 "2018-05-15T13:53:41Z")

</div>

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