In JSON documents, dates are represented as strings. Elasticsearch uses a set of preconfigured formats to recognize and parse these strings into a long value representing milliseconds-since-the-epoch in UTC.
Besides the built-in formats, your own custom formats can be specified using the familiar yyyy/MM/dd
syntax:
PUT my-index-000001
{ "mappings": { "properties": { "date": { "type": "date", "format": "yyyy-MM-dd" } } } }
Many APIs which support date values also support date math expressions, such as now-1m/d
â the current time, minus one month, rounded down to the nearest day.
Completely customizable date formats are supported. The syntax for these is explained in DateTimeFormatter docs.
Note that while the built-in formats for week dates use the ISO definition of weekyears, custom formatters using the Y
, W
, or w
field specifiers use the JDK locale definition of weekyears. This can result in different values between the built-in formats and custom formats for week dates.
Most of the below formats have a strict
companion format, which means that year, month and day parts of the month must use respectively 4, 2 and 2 digits exactly, potentially prepending zeros. For instance a date like 5/11/1
would be considered invalid and would need to be rewritten to 2005/11/01
to be accepted by the date parser.
To use them, you need to prepend strict_
to the name of the date format, for instance strict_date_optional_time
instead of date_optional_time
.
These strict date formats are especially useful when date fields are dynamically mapped in order to make sure to not accidentally map irrelevant strings as dates.
The following tables lists all the defaults ISO formats supported:
epoch_millis
Long.MIN_VALUE
and Long.MAX_VALUE
.
epoch_second
Long.MIN_VALUE
and Long. MAX_VALUE
divided by 1000 (the number of milliseconds in a second).
date_optional_time
or strict_date_optional_time
A generic ISO datetime parser, where the date must include the year at a minimum, and the time (separated by T
), is optional. Examples: yyyy-MM-dd'T'HH:mm:ss.SSSZ
or yyyy-MM-dd
.
NOTE: When using `date_optional_time`, the parsing is lenient and will attempt to parse
numbers as a year (e.g. `292278994` will be parsed as a year). This can lead to unexpected results
when paired with a numeric focused format like `epoch_second` and `epoch_millis`.
It is recommended you use `strict_date_optional_time` when pairing with a numeric focused format.
strict_date_optional_time_nanos
T
), is optional. The fraction of a second part has a nanosecond resolution. Examples: yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ
or yyyy-MM-dd
.
basic_date
yyyyMMdd
.
basic_date_time
yyyyMMdd'T'HHmmss.SSSZ
.
basic_date_time_no_millis
yyyyMMdd'T'HHmmssZ
.
basic_ordinal_date
yyyyDDD
.
basic_ordinal_date_time
yyyyDDD'T'HHmmss.SSSZ
.
basic_ordinal_date_time_no_millis
yyyyDDD'T'HHmmssZ
.
basic_time
HHmmss.SSSZ
.
basic_time_no_millis
HHmmssZ
.
basic_t_time
'T'HHmmss.SSSZ
.
basic_t_time_no_millis
'T'HHmmssZ
.
basic_week_date
or strict_basic_week_date
xxxx'W'wwe
.
basic_week_date_time
or strict_basic_week_date_time
xxxx'W'wwe'T'HHmmss.SSSZ
.
basic_week_date_time_no_millis
or strict_basic_week_date_time_no_millis
xxxx'W'wwe'T'HHmmssZ
.
date
or strict_date
yyyy-MM-dd
.
date_hour
or strict_date_hour
yyyy-MM-dd'T'HH
.
date_hour_minute
or strict_date_hour_minute
yyyy-MM-dd'T'HH:mm
.
date_hour_minute_second
or strict_date_hour_minute_second
yyyy-MM-dd'T'HH:mm:ss
.
date_hour_minute_second_fraction
or strict_date_hour_minute_second_fraction
yyyy-MM-dd'T'HH:mm:ss.SSS
.
date_hour_minute_second_millis
or strict_date_hour_minute_second_millis
yyyy-MM-dd'T'HH:mm:ss.SSS
.
date_time
or strict_date_time
yyyy-MM-dd'T'HH:mm:ss.SSSZ
.
date_time_no_millis
or strict_date_time_no_millis
yyyy-MM-dd'T'HH:mm:ssZ
.
hour
or strict_hour
HH
hour_minute
or strict_hour_minute
HH:mm
.
hour_minute_second
or strict_hour_minute_second
HH:mm:ss
.
hour_minute_second_fraction
or strict_hour_minute_second_fraction
HH:mm:ss.SSS
.
hour_minute_second_millis
or strict_hour_minute_second_millis
HH:mm:ss.SSS
.
ordinal_date
or strict_ordinal_date
yyyy-DDD
.
ordinal_date_time
or strict_ordinal_date_time
yyyy-DDD'T'HH:mm:ss.SSSZ
.
ordinal_date_time_no_millis
or strict_ordinal_date_time_no_millis
yyyy-DDD'T'HH:mm:ssZ
.
time
or strict_time
HH:mm:ss.SSSZ
.
time_no_millis
or strict_time_no_millis
HH:mm:ssZ
.
t_time
or strict_t_time
'T'HH:mm:ss.SSSZ
.
t_time_no_millis
or strict_t_time_no_millis
'T'HH:mm:ssZ
.
week_date
or strict_week_date
YYYY-'W'ww-e
. This uses the ISO week-date definition.
week_date_time
or strict_week_date_time
YYYY-'W'ww-e'T'HH:mm:ss.SSSZ
. This uses the ISO week-date definition.
week_date_time_no_millis
or strict_week_date_time_no_millis
YYYY-'W'ww-e'T'HH:mm:ssZ
. This uses the ISO week-date definition.
weekyear
or strict_weekyear
YYYY
. This uses the ISO week-date definition.
weekyear_week
or strict_weekyear_week
YYYY-'W'ww
. This uses the ISO week-date definition.
weekyear_week_day
or strict_weekyear_week_day
YYYY-'W'ww-e
. This uses the ISO week-date definition.
year
or strict_year
yyyy
.
year_month
or strict_year_month
yyyy-MM
.
year_month_day
or strict_year_month_day
A formatter for a four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4