This code snippet works absolutely fine. The only problem is, I might have a thousand nested fields in the future in the JSON, and parsing like this would create a very ugly-looking configuration file as there will be a thousand number of if conditions I will have to add before adding them in mutating fields.
I wanted to know, Is there any better way to deal with this which can reduce these if conditions or eliminate them at all with a better alternative.
Please help me here if you know something or have gone through a scenario like this.
But this solution is throwing an error for a field which is already configured before scripting ruby.
[2021-02-23T22:56:12,674][ERROR][logstash.filters.ruby ][main][c1ecdd2dc6b4374ad48846533a8813f0fad9b1a694695b8bcafdb43287264129] Ruby exception occurred: undefined local variable or method `payload' for #<LogStash::Filters::Ruby:0x58283990>
[2021-02-23T22:56:12,722][ERROR][logstash.filters.ruby ][main][c1ecdd2dc6b4374ad48846533a8813f0fad9b1a694695b8bcafdb43287264129] Ruby exception occurred: undefined local variable or method `payload' for #<LogStash::Filters::Ruby:0x58283990>
[2021-02-23T22:56:12,885][ERROR][logstash.filters.ruby ][main][c1ecdd2dc6b4374ad48846533a8813f0fad9b1a694695b8bcafdb43287264129] Ruby exception occurred: undefined local variable or method `payload' for #<LogStash::Filters::Ruby:0x58283990>
[2021-02-23T22:56:12,941][ERROR][logstash.filters.ruby ][main][c1ecdd2dc6b4374ad48846533a8813f0fad9b1a694695b8bcafdb43287264129] Ruby exception occurred: undefined local variable or method `payload' for #<LogStash::Filters::Ruby:0x58283990>
[2021-02-23T22:56:12,970][ERROR][logstash.filters.ruby ][main][c1ecdd2dc6b4374ad48846533a8813f0fad9b1a694695b8bcafdb43287264129] Ruby exception occurred: undefined local variable or method `payload' for #<LogStash::Filters::Ruby:0x58283990>
That is telling you that [data][content][payload] is a Hash, not an Array. It may be that when there is only one Array member it just presents a Hash instead of an Array of Hash, in which case you could change the ruby file to us
if payload.is_a? Array
instead of
if payload
For you other question I cannot answer without seeing what the data looks like.
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.