0

I'm using logstash aggregate filter plugin to insert data to ES.

I want to create a json like

"Countries" : {
        "Asia" : {
            "name" : "Srilanka"
        },
        "Africa" : {
            "name" : "Kenya"
        }
    }

when uploaded to ES.

I have tried

map['Countries'] = {
        map['Asia'] =  {
            'name' => event.get('name_Asia')
        },
        map['Africa'] =  {
            'name' => event.get('name_Africa')
        }
}

But it doesn't work.

Is it possible to make create above json?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

3

In the first place to produce nested hashes, you should use hashrockets => not assignments inside a hash. One might create this hash in one turn:

map = { 
  'Countries' => {
    'Asia' =>  {
      'name' => event.get('name_Asia')
    },
    'Africa' => {
      'name' => event.get('name_Africa')
    }
  }
}

Then you can produce JSON out of it with JSON.dump

require 'json'
JSON.dump(map)
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160