Date field type
- A long value that corresponds to milliseconds since the epoch (the value must be non-negative). Dates are stored in this form internally.
- A formatted string.
- An integer value that corresponds to seconds since the epoch (the value must be non-negative).
To represent date ranges, there is a date range field type.
Create a mapping with a date field and two date formats:
The following table lists the parameters accepted by date field types. All parameters are optional.
Most of the date formats have a strict_
counterpart. When the format starts with strict_
, the date must have the correct number of digits specified in the format. For example, if the format is set to strict_year_month_day
(“yyyy-MM-dd”), both month and day have to be two-digit numbers. So, “2020-06-09” is valid, while “2020-6-9” is invalid.
Epoch is defined as 00:00:00 UTC on January 1, 1970.
y: year
Y:
M: month
w: ordinal week of the year from 01 to 53
d: day
D: ordinal day of the year from 001 to 365 (366 for leap years)
e: ordinal day of the week from 1 (Monday) to 7 (Sunday)
H: hour from 0 to 23
m: minute
s: second
S: fraction of a second
Z: time zone offset (for example, +0400; -0400; -04:00)
Components of full date formats are separated by a -
delimiter for date and :
delimiter for time. For example, “2019-03-23T21:34”.
You can create custom formats for date fields. For example, the following request specifies a date in the common “MM/dd/yyyy” format.
Index a document with a date:
Range queries by default use the field’s mapped format. You can also specify the range of dates in a different format by providing the parameter: