The date filter is used for parsing dates from fields, and then using that date or timestamp as the logstash timestamp for the event.
For example, syslog events usually have timestamps like this:
"Apr 17 09:32:01"
You would use the date format “MMM dd HH:mm:ss” to parse this.
The date filter is especially important for sorting events and for backfilling old data. If you don’t get the date correct in your event, then searching for them later will likely sort out of order.
In the absence of this filter, logstash will choose a timestamp based on the first time it sees the event (at input time), if the timestamp is not already set in the event. For example, with file input, the timestamp is set to the time of each read.
filter {
date {
add_field => ... # hash (optional), default: {}
add_tag => ... # array (optional), default: []
locale => ... # string (optional)
match => ... # array (optional), default: []
remove_field => ... # array (optional), default: []
remove_tag => ... # array (optional), default: []
target => ... # string (optional), default: "@timestamp"
timezone => ... # string (optional)
}
}
If this filter is successful, add any arbitrary fields to this event. Field names can be dynamic and include parts of the event using the %{field} Example:
filter {
date {
add_field => { "foo_%{somefield}" => "Hello world, from %{host}" }
}
}
# You can also add multiple fields at once:
filter {
date {
add_field => {
"foo_%{somefield}" => "Hello world, from %{host}"
"new_field" => "new_static_value"
}
}
}
If the event has field “somefield” == “hello” this filter, on success, would add field “foo_hello” if it is present, with the value above and the %{host} piece replaced with that value from the event. The second example would also add a hardcoded field.
If this filter is successful, add arbitrary tags to the event. Tags can be dynamic and include parts of the event using the %{field} syntax. Example:
filter {
date {
add_tag => [ "foo_%{somefield}" ]
}
}
# You can also add multiple tags at once:
filter {
date {
add_tag => [ "foo_%{somefield}", "taggedy_tag"]
}
}
If the event has field “somefield” == “hello” this filter, on success, would add a tag “foo_hello” (and the second example would of course add a “taggedy_tag” tag).
Only handle events without all/any (controlled by exclude_any config option) of these tags. Optional.
Specify a locale to be used for date parsing. If this is not specified, the platform default will be used.
The locale is mostly necessary to be set for parsing month names and weekday names.
The date formats allowed are anything allowed by Joda-Time (java time library). You can see the docs for this format here:
joda.time.format.DateTimeFormat
An array with field name first, and format patterns following, [ field,
formats... ]
If your time field has multiple possible formats, you can do this:
match => [ "logdate", "MMM dd YYY HH:mm:ss",
"MMM d YYY HH:mm:ss", "ISO8601" ]
The above will match a syslog (rfc3164) or iso8601 timestamp.
There are a few special exceptions. The following format literals exist to help you save time and ensure correctness of date parsing.
For example, if you have a field ‘logdate’, with a value that looks like ‘Aug 13 2010 00:03:44’, you would use this configuration:
filter {
date {
match => [ "logdate", "MMM dd YYYY HH:mm:ss" ]
}
}
If your field is nested in your structure, you can use the nested syntax [foo][bar] to match its value. For more information, please refer to http://logstash.net/docs/latest/configuration#fieldreferences
If this filter is successful, remove arbitrary fields from this event. Fields names can be dynamic and include parts of the event using the %{field} Example:
filter {
date {
remove_field => [ "foo_%{somefield}" ]
}
}
# You can also remove multiple fields at once:
filter {
date {
remove_field => [ "foo_%{somefield}" "my_extraneous_field" ]
}
}
If the event has field “somefield” == “hello” this filter, on success, would remove the field with name “foo_hello” if it is present. The second example would remove an additional, non-dynamic field.
If this filter is successful, remove arbitrary tags from the event. Tags can be dynamic and include parts of the event using the %{field} syntax. Example:
filter {
date {
remove_tag => [ "foo_%{somefield}" ]
}
}
# You can also remove multiple tags at once:
filter {
date {
remove_tag => [ "foo_%{somefield}", "sad_unwanted_tag"]
}
}
If the event has field “somefield” == “hello” this filter, on success, would remove the tag “foo_hello” if it is present. The second example would remove a sad, unwanted tag as well.
Only handle events with all/any (controlled by include_any config option) of these tags. Optional.
Store the matching timestamp into the given target field. If not provided, default to updating the @timestamp field of the event.
Specify a time zone canonical ID to be used for date parsing.
The valid IDs are listed on the Joda.org available time zones page.
This is useful in case the time zone cannot be extracted from the value,
and is not the platform default.
If this is not specified the platform default will be used.
Canonical ID is good as it takes care of daylight saving time for you
For example, America/Los_Angeles
or Europe/France
are valid IDs.
Note that all of the specified routing options (type,tags.exclude_tags,include_fields,exclude_fields) must be met in order for the event to be handled by the filter. The type to act on. If a type is given, then this filter will only act on messages with the same type. See any input plugin’s “type” attribute for more. Optional.