For other versions, see theVersioned plugin docs.
For questions about the plugin, open a topic in the Discuss forums. For bugs or feature requests, open an issue in Github.For the list of Elastic supported plugins, please consult the Elastic Support Matrix.
The date filter is used for parsing dates from fields, and then using thatdate 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 forbackfilling old data. If you don’t get the date correct in yourevent, then searching for them later will likely sort out of order.
In the absence of this filter, logstash will choose a timestamp based on thefirst time it sees the event (at input time), if the timestamp is not alreadyset in the event. For example, with file input, the timestamp is set to thetime of each read.
This plugin supports the following configuration options plus the Common Options described later.
Setting | Input type | Required |
---|---|---|
No |
||
No |
||
No |
||
No |
||
No |
Also see Common Options for a list of options supported by allfilter plugins.
Specify a locale to be used for date parsing using either IETF-BCP47 or POSIX language tag.Simple examples are en
,en-US
for BCP47 or en_US
for POSIX.
The locale is mostly necessary to be set for parsing month names (pattern with MMM
) andweekday names (pattern with EEE
).
If not specified, the platform default will be used but for non-english platform defaultan english parser will also be used as a fallback mechanism.
[]
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 yyyy HH:mm:ss", "MMM d yyyy HH:mm:ss", "ISO8601" ]
The above will match a syslog (rfc3164) or iso8601
timestamp.
There are a few special exceptions. The following format literals existto help you save time and ensure correctness of date parsing.
ISO8601
- should parse any valid ISO8601 timestamp, such as 2011-04-19T03:44:01.103Z
UNIX
- will parse float or int value expressing unix time in seconds since epoch like 1326149001.132 as well as 1326149001UNIX_MS
- will parse int value expressing unix time in milliseconds since epoch like 1366125117000TAI64N
- will parse tai64n time valuesFor example, if you have a field logdate
, with a value that looks likeAug 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 nestedsyntax [foo][bar]
to match its value. For more information, please refer toField References
More details on the syntax
The syntax used for parsing date and time text uses letters to indicate thekind of time value (month, minute, etc), and a repetition of letters toindicate the form of that value (2-digit month, full month name, etc).
Here’s what you can use to parse dates and times:
y |
year
|
M |
month of the year
|
d |
day of the month
|
H |
hour of the day (24-hour clock)
|
m |
minutes of the hour (60 minutes per hour)
|
s |
seconds of the minute (60 seconds per minute)
|
S |
fraction of a second Maximum precision is milliseconds (
|
Z |
time zone offset or identity
|
z |
time zone names. Time zone names (z) cannot be parsed. |
w |
week of the year
|
D |
day of the year |
e |
day of the week (number) |
E |
day of the week (text)
|
For non-formatting syntax, you’ll need to put single-quote characters around the value. For example, if you were parsing ISO8601 time, "2015-01-01T01:12:23" that little "T" isn’t a valid time format, and you want to say "literally, a T", your format would be this: "yyyy-MM-dd’T'HH:mm:ss"
Other less common date units, such as era (G), century (C), am/pm (a), and # more, can be learned about on thejoda-time documentation.
["_dateparsefailure"]
Append values to the tags
field when there has been nosuccessful match
"@timestamp"
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 youFor example, America/Los_Angeles
or Europe/Paris
are valid IDs.This field can be dynamic and include parts of the event using the %{field}
syntax
The following configuration options are supported by all filter plugins:
Setting | Input type | Required |
---|---|---|
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
{}
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 thevalue above and the %{host}
piece replaced with that value from theevent. 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).
true
Disable or enable metric logging for this specific plugin instanceby default we record all the metrics we can, but you can disable metrics collectionfor a specific plugin.
Add a unique ID
to the plugin configuration. If no ID is specified, Logstash will generate one.It is strongly recommended to set this ID in your configuration. This is particularly usefulwhen you have two or more plugins of the same type, for example, if you have 2 date filters.Adding a named ID in this case will help in monitoring Logstash when using the monitoring APIs.
filter { date { id => "ABC" }}
false
Call the filter flush method at regular interval.Optional.
[]
If this filter is successful, remove arbitrary fields from this event.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 secondexample 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 examplewould remove a sad, unwanted tag as well.