Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert feature of mutate filter does not work for a added field that was created using % #57

Open
mursabogdan opened this issue Nov 4, 2015 · 3 comments

Comments

@mursabogdan
Copy link

Hello.

I have a problem regarding the mutate filter.

To be more specific, in a logstash config, I added a new field like this:

filter {
if [type] == "syslog" {
grok {
match => { "message" => "%{IPORHOST:remote_ip} %{IPORHOST:client_ip} %{USER:ident} %{USER:auth} [%{HTTPDATE:timestamp}] %{NUMBER:response_time} "%{NOTSPACE:request} %{NOTSPACE:route} %{NOTSPACE:protocol}" %{NUMBER:response_code} %{NUMBER:response_size} "%{DATA:referer}" "%{DATA:user_agent}"" }
}
mutate {
add_field => [ "response_code_%{response_code}", 1 ]
}
mutate {
convert => [ "response_code_%{response_code}", "integer" ]
}
mutate {
convert => {
"response_code" => "integer"
"response_size" => "integer"
"response_time" => "integer"
"offset" => "integer"
}
}
}
}

So, for example if the response_code is 200 I expect a new field "response_code_200" with value 1.
{
....
"response_code_200" => "1"
}

All good until here, since I know that by default when you add a numerical value to a new field it is made string.

The problem is in the next section of mutate, when I try to convert to integer. I can't manage to convert the value to integer under any circumstances.
I receive as output always a string.

{
....
"response_code_200" => "1"
}

I tried as well to add_field/ convert using hash syntax, still no result.

mutate {
add_field => { "response_code_%{response_code}" => 1 }
}
mutate {
convert => { "response_code_%{response_code}" => "integer" }
}

A big observation was that if I don't use %{response_code} in the key name in the conversion phase, everything works.

E.g: response_code = 200

mutate {
add_field => { "response_code_%{response_code}" => 1 }
}
mutate {
convert => { "response_code_200}" => "integer" }
}

OUTPUT:
{
....
"response_code_200" => 1
}

I look forward to hearing from you,
Bogdan Mursa.

@dmarkhas
Copy link

There doesn't seem to be any solution for this, except for using Ruby filter directly.

@GogLlundain
Copy link

Can we add this as a feature request? How do we do that?

@pallix
Copy link

pallix commented Oct 16, 2018

I think it would be very useful to convert fields automatically or based on regexp matching the fields names. It would be a useful complement to the kv filter which create dynamically fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants