format
edit
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 millisecondssincetheepoch in UTC.
Besides the builtin formats, your own
custom formats can be specified using the familiar
yyyy/MM/dd
syntax:
PUT my_index { "mappings": { "properties": { "date": { "type": "date", "format": "yyyyMMdd" } } } }
Many APIs which support date values also support date math
expressions, such as now1m/d
— the current time, minus one month, rounded
down to the nearest day.
Custom date formatsedit
Completely customizable date formats are supported. The syntax for these is explained DateTimeFormatter docs.
Built In Formatsedit
Most of the below formats have a strict
companion format, which means that
year, month and day parts of the week 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

A formatter for the number of milliseconds since the epoch. Note, that
this timestamp is subject to the limits of a Java
Long.MIN_VALUE
andLong.MAX_VALUE
. 
epoch_second

A formatter for the number of seconds since the epoch. Note, that this
timestamp is subject to the limits of a Java
Long.MIN_VALUE
andLong. MAX_VALUE
divided by 1000 (the number of milliseconds in a second). 
date_optional_time
orstrict_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:yyyyMMdd'T'HH:mm:ss.SSSZ
oryyyyMMdd
. 
strict_date_optional_time_nanos

A generic ISO datetime parser, where the date must include the year at a minimum, and the time
(separated by
T
), is optional. The fraction of a second part has a nanosecond resolution. Examples:yyyyMMdd'T'HH:mm:ss.SSSSSSZ
oryyyyMMdd
. 
basic_date

A basic formatter for a full date as four digit year, two digit month of
year, and two digit day of month:
yyyyMMdd
. 
basic_date_time

A basic formatter that combines a basic date and time, separated by a T:
yyyyMMdd'T'HHmmss.SSSZ
. 
basic_date_time_no_millis

A basic formatter that combines a basic date and time without millis,
separated by a T:
yyyyMMdd'T'HHmmssZ
. 
basic_ordinal_date

A formatter for a full ordinal date, using a four digit year and three
digit dayOfYear:
yyyyDDD
. 
basic_ordinal_date_time

A formatter for a full ordinal date and time, using a four digit year and
three digit dayOfYear:
yyyyDDD'T'HHmmss.SSSZ
. 
basic_ordinal_date_time_no_millis

A formatter for a full ordinal date and time without millis, using a four
digit year and three digit dayOfYear:
yyyyDDD'T'HHmmssZ
. 
basic_time

A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, three digit millis, and time zone offset:
HHmmss.SSSZ
. 
basic_time_no_millis

A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, and time zone offset:
HHmmssZ
. 
basic_t_time

A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, three digit millis, and time zone off set
prefixed by T:
'T'HHmmss.SSSZ
. 
basic_t_time_no_millis

A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, and time zone offset prefixed by T:
'T'HHmmssZ
. 
basic_week_date
orstrict_basic_week_date

A basic formatter for a full date as four digit weekyear, two digit week
of weekyear, and one digit day of week:
xxxx'W'wwe
. 
basic_week_date_time
orstrict_basic_week_date_time

A basic formatter that combines a basic weekyear date and time, separated
by a T:
xxxx'W'wwe'T'HHmmss.SSSZ
. 
basic_week_date_time_no_millis
orstrict_basic_week_date_time_no_millis

A basic formatter that combines a basic weekyear date and time without
millis, separated by a T:
xxxx'W'wwe'T'HHmmssZ
. 
date
orstrict_date

A formatter for a full date as four digit year, two digit month of year,
and two digit day of month:
yyyyMMdd
. 
date_hour
orstrict_date_hour

A formatter that combines a full date and two digit hour of day:
yyyyMMdd'T'HH
. 
date_hour_minute
orstrict_date_hour_minute

A formatter that combines a full date, two digit hour of day, and two
digit minute of hour:
yyyyMMdd'T'HH:mm
. 
date_hour_minute_second
orstrict_date_hour_minute_second

A formatter that combines a full date, two digit hour of day, two digit
minute of hour, and two digit second of minute:
yyyyMMdd'T'HH:mm:ss
. 
date_hour_minute_second_fraction
orstrict_date_hour_minute_second_fraction

A formatter that combines a full date, two digit hour of day, two digit
minute of hour, two digit second of minute, and three digit fraction of
second:
yyyyMMdd'T'HH:mm:ss.SSS
. 
date_hour_minute_second_millis
orstrict_date_hour_minute_second_millis

A formatter that combines a full date, two digit hour of day, two digit
minute of hour, two digit second of minute, and three digit fraction of
second:
yyyyMMdd'T'HH:mm:ss.SSS
. 
date_time
orstrict_date_time

A formatter that combines a full date and time, separated by a T:
yyyyMMdd'T'HH:mm:ss.SSSZZ
. 
date_time_no_millis
orstrict_date_time_no_millis

A formatter that combines a full date and time without millis, separated
by a T:
yyyyMMdd'T'HH:mm:ssZZ
. 
hour
orstrict_hour

A formatter for a two digit hour of day:
HH

hour_minute
orstrict_hour_minute

A formatter for a two digit hour of day and two digit minute of hour:
HH:mm
. 
hour_minute_second
orstrict_hour_minute_second

A formatter for a two digit hour of day, two digit minute of hour, and two
digit second of minute:
HH:mm:ss
. 
hour_minute_second_fraction
orstrict_hour_minute_second_fraction

A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and three digit fraction of second:
HH:mm:ss.SSS
. 
hour_minute_second_millis
orstrict_hour_minute_second_millis

A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and three digit fraction of second:
HH:mm:ss.SSS
. 
ordinal_date
orstrict_ordinal_date

A formatter for a full ordinal date, using a four digit year and three
digit dayOfYear:
yyyyDDD
. 
ordinal_date_time
orstrict_ordinal_date_time

A formatter for a full ordinal date and time, using a four digit year and
three digit dayOfYear:
yyyyDDD'T'HH:mm:ss.SSSZZ
. 
ordinal_date_time_no_millis
orstrict_ordinal_date_time_no_millis

A formatter for a full ordinal date and time without millis, using a four
digit year and three digit dayOfYear:
yyyyDDD'T'HH:mm:ssZZ
. 
time
orstrict_time

A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, three digit fraction of second, and time zone
offset:
HH:mm:ss.SSSZZ
. 
time_no_millis
orstrict_time_no_millis

A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and time zone offset:
HH:mm:ssZZ
. 
t_time
orstrict_t_time

A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, three digit fraction of second, and time zone
offset prefixed by T:
'T'HH:mm:ss.SSSZZ
. 
t_time_no_millis
orstrict_t_time_no_millis

A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and time zone offset prefixed by T:
'T'HH:mm:ssZZ
. 
week_date
orstrict_week_date

A formatter for a full date as four digit weekyear, two digit week of
weekyear, and one digit day of week:
xxxx'W'wwe
. 
week_date_time
orstrict_week_date_time

A formatter that combines a full weekyear date and time, separated by a
T:
xxxx'W'wwe'T'HH:mm:ss.SSSZZ
. 
week_date_time_no_millis
orstrict_week_date_time_no_millis

A formatter that combines a full weekyear date and time without millis,
separated by a T:
xxxx'W'wwe'T'HH:mm:ssZZ
. 
weekyear
orstrict_weekyear

A formatter for a four digit weekyear:
xxxx
. 
weekyear_week
orstrict_weekyear_week

A formatter for a four digit weekyear and two digit week of weekyear:
xxxx'W'ww
. 
weekyear_week_day
orstrict_weekyear_week_day

A formatter for a four digit weekyear, two digit week of weekyear, and one
digit day of week:
xxxx'W'wwe
. 
year
orstrict_year

A formatter for a four digit year:
yyyy
. 
year_month
orstrict_year_month

A formatter for a four digit year and two digit month of year:
yyyyMM
. 
year_month_day
orstrict_year_month_day

A formatter for a four digit year, two digit month of year, and two digit
day of month:
yyyyMMdd
.