Sorry if it is a duplicated post.
I have been searching google and the forum for answer, however I still could not find it.
It would be nice if someone can direct me to the answer if it is duplicated.
I am currently using Logstash to receive some of my logs via UDP and save it to the file.
The content sent to Logstash is as follow:
{
"key1":"value1",
"key2":"value2",
"key3":"value3",
"key4":"value4"
}
and in my output file looks like:
{
"message": {
"key1":"value1",
"key2":"value2",
"key3":"value3",
"key4":"value4"
},
"@timestamp":"....."
}
desired output file:
{
"key1":"value1",
"key2":"value2",
"key3":"value3",
"key4":"value4",
"@timestamp":"....."
}
I am hoping to extract all key and value to the top level rather than storing in message.
I am aware I can use mutate.addfield but that means if I have 50 key, my add_field would have 50 entry.
mutate {
add_field => {
"key1" => "%{[message][key1]}"
}
}
I am looking for a better solution to it, so that all key in message can be extracted to the top level.
I am currently using Logstash 6.4.2
From what I have now in my filter without add_field:
filter {
json {
source => "message"
target => "message"
}
mutate {
remove_field => ["tags","@version","host"]
}
}