Hello,
I use logstash 7.17.
I want to create a field while looping through an array in ruby from my data. Here is a snippet of my code which doesn't work :
items_contact = event.get("[contactMedium]")
if items_contact != nil
items_contact.each_with_index { |i, x|
if (i["mediumType"] == "address") then
if i["characteristic"]["street"] then
event.set("[user][address]", i["characteristic"]["street"])
end
if i["characteristic"]["city"] then
event.set("[user][city]", i["characteristic"]["city"])
end
elsif (i["mediumType"] == "contact") then
if i["characteristic"]["contactNumber"] then
event.set("[user][contactNumber]", i["characteristic"]["contactNumber"])
end
elsif (i["mediumType"] == "email") then
if i["characteristic"]["email"] then
event.set("[user][email]", i["characteristic"]["email"])
end
end
}
end
Here is my input in json :
{
"contactMedium": [
{ "mediumType": "address", "characteristic": { "city": "Paris", "street": "2 rue bidule" } },
{ "mediumType": "email", "characteristic": { "email": "test@test.com" } },
{ "mediumType": "contact", "characteristic": { "contactNumber": "0600000000"} }
]
}
Here is what I want:
"user": {
"address": "2 rue bidule",
"city": "France",
"contactNumber": "0600000000",
"email": "test@test.com"
}
How can I create these fields while in a loop ?
Any help would be appreciated, thank you in advance