The only thing that is certain about [url][queryString] is that it begins with 404; or that the key is long.I need to remove such keys. If I use the ruby code below it gives cannot convert linked hashmap to string exception.
input {
file {
# Wildcards work, here :)
path => ["C:\Users\ppurush\Desktop\test\*.log"]
start_position => "beginning"
}
}
filter {
ruby {
code=>
"
require json
my_hash = JSON.parse([url][queryString])
my_hash.delete_if { |key,value| key.to_s.match(/^404;/) }
"
}
}
output {
stdout{}
elasticsearch {
host => localhost
}
}
You get a ruby exception because your ruby code is invalid. Try this instead:
This works if your event has a
'url' => 'queryString'
field which contains valid json. You might already have some kind of filter to achieve this (e.g. grok). You might also consider using logstash's built-in json filter and maybe drop to delete certain events.EDIT:
Suppose your input is plain json (I had to tidy this up):
You can use
codec => "json"
in your file input.You will get a field:
So
404;dfdgfdgfghfhjghhhhhhhhhhhhh
is a variable, too. To check for it and delete the event you could do something like this: