Hi,
i retrieved data from ES and would like to add/modify the json data before index it.
My json data looks like below:
{ "john" : { "enabled" : true, "roles" : [ "developer" ], "rules" : { "any" : [ { "field" : { "dn" : "CN=john,OU=IT,OU=MY,DC=DomainName,DC=local" } } ] }, "metadata" : { } }, "shyap" : { "enabled" : true, "roles" : [ "superuser", "reportinguser" ], "rules" : { "any" : [ { "field" : { "dn" : "CN=shyap,OU=IT,OU=MY,DC=DomainName,DC=local" } } ] }, "metadata" : { } } }
My config file:
input { http_poller { urls => { test1 => { method => get user => "elastic" password => "changeme" url => "https://hostname:9200/_security/role_mapping" headers => { Accept => "application/json" } } } request_timeout => 60 schedule => {"every" => "2s"} codec => "json" cacert => "/etc/elasticsearch/certs/root2016.crt" } } filter { json { source => "message" } mutate { remove_field => ["@timestamp"] remove_field => ["@version"] remove_field => ["message"] } } output { stdout { codec => rubydebug } }
This is the role mapping data.
I would like to know how do i transform the data into following:
First step i am trying is to add new field 'userid' and give the value of 'shyap' and 'john'.
When i put in the 'add_field' option, nothing happne.
i use following json filter:
json { source => "message" add_field => {"userid" => "%{[message][0]}"} }
However, if i use mutate filter, i get only one userid field added. Somehow, the two records were treated as one?
{ "shyap" => { "enabled" => true, "roles" => [ [0] "superuser", [1] "reportinguser" ], "rules" => { "any" => [ [0] { "field" => { "dn" => "CN=shyap,OU=IT,OU=MY,DC=DomainName,DC=local" } } ] }, "metadata" => {} }, "userid" => "%{[message][0]}", "john" => { "enabled" => true, "roles" => [ [0] "developer" ], "rules" => { "any" => [ [0] { "field" => { "dn" => "CN=john,OU=IT,OU=MY,DC=DomainName,DC=local" } } ] }, "metadata" => {} } }
Can someone guide me how do i proceed ?
Thanks in advance.