I would like to have some assistance on how to add a nested field array to a new field based on the key string value.
As you can see in the json output below, I am simply trying to add the nested field [properties][additionalDetails][value]] if "key" = "invitedUserEmailAddress"
I think you'll have to use Ruby: Iterate over [properties][additionalDetails] and if the string in key is the one you are looking for, fill the field EmailAddress with value.
It's similar to this: Ruby code for array iteration
That looks nearly right. Use item['value] to access the value within your loop. And wrap your code in double quotes if you use single quotes in the code.
I was talking about the value. You used the correct code to use the key in Ruby. But when you needed the value, you just wrote '[properties][additionalDetails][value]' which would literally just insert the string '[properties][additionalDetails][value]' into the field EmailAddress.
If you change the quotes at both places, it won't help at all. The point is that the programming language needs to know which quotes belong to each other. If you write ' to say "This is where my ruby code begins" and then use ' again to say "This is where a string in my ruby code begins", it won't work. What the computer sees is event.get( (the text between the first '...') as the code that you want to execute and a lot of nonsense after that, that doesn't belong there. Then it will cry "syntax error!" and do nothing.
ruby {
code => "
event.get('[properties][additionalDetails]').each do |item|
if item['key'] == 'invitedUserEmailAddress'
event.set('EmailAddress', item['value'])
end
end
"
}
Seems like this ruby code is invalid according to logstash pipeline.
[FATAL] 2020-06-30 17:11:04.597 [LogStash::Runner] runner - The given configuration is invalid. Reason: Expected one of [ \t\r\n], "#", "{", "}" at line 23, column 25 (byte 519) after filter {
Perhaps you did not understand what Jenni was saying. If your code contains double quotes then surround it in single quotes. Change this to
ruby {
code => '
event.get("[properties][additionalDetails]").each do |item|
if item["key"] == "invitedUserEmailAddress"
event.set("EmailAddress", item["value"])
end
end
'
}
With this ruby code, is there a way to not specify the new field "EmailAddress" if the nested field array value "key" does not equal "invitedUserEmailAddress"
It is because I am seeing this in my index too:
Or instead of seeing the value "def" to at least show "-" or null ?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.