logstash-plugins / logstash-filter-date

Apache License 2.0
7 stars 43 forks source link

add_field doesn't appear to work using date filter #131

Open krisATelastic opened 5 years ago

krisATelastic commented 5 years ago
input { stdin { codec => json } }

filter {
  date {
    add_field => { "logtimestamp" => "%{[date]} %{[time]}" }
    match => [ "logtimestamp", "dd/MM/yy HH:mm:ss.SSSSSS" ]
  }
}

output { stdout {} }

filter { mutate { add_field => { "logtimestamp" => "%{[date]} %{[time]}" } } date { match => [ "logtimestamp", "dd/MM/yy HH:mm:ss.SSSSSS" ] } }

output { stdout {} }

Output

{ "@timestamp" => 2025-04-19T00:20:34.443Z, "host" => "lstest", "date" => "19/04/25", "time" => "10:20:34.443879", "@version" => "1", "logtimestamp" => "19/04/25 10:20:34.443879" }

TheVastyDeep commented 5 years ago

That is expected. add_field is one of the common options ("decoration") that is performed when a filter has successfully executed. Also, the date filter is a no-op if the field to be matched does not exist. So the filter does not successfully match the field, so it does not add_field you are asking it to match.