diff --git a/_field-types/supported-field-types/date.md b/_field-types/supported-field-types/date.md index 5bd52a83..e0b99f3a 100644 --- a/_field-types/supported-field-types/date.md +++ b/_field-types/supported-field-types/date.md @@ -66,7 +66,7 @@ As of OpenSearch 2.12, the default date format is `strict_date_time_no_millis||s ## Built-in formats -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. +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. {: .note } @@ -99,70 +99,71 @@ Components of basic date formats are not separated by a delimiter. For example, Format name and description | Pattern and examples :--- | :--- **Dates**| -`basic_date_time`
A basic date and time separated by `T`. | "yyyyMMdd`T`HHmmss.SSSZ"
"20190323T213446.123-04:00" -`basic_date_time_no_millis`
A basic date and time without milliseconds, separated by `T`. | "yyyyMMdd`T`HHmmssZ"
"20190323T213446-04:00" -`basic_date`
A date with a four-digit year, two-digit month, and two-digit day. | "yyyyMMdd"
"20190323" +`basic_date_time`
A basic date and time separated by `T`. | `"yyyyMMdd`T`HHmmss.SSSZ"`
`"20190323T213446.123-04:00"` +`basic_date_time_no_millis`
A basic date and time without milliseconds, separated by `T`. | `"yyyyMMdd`T`HHmmssZ"`
`"20190323T213446-04:00"` +`basic_date`
A date with a four-digit year, two-digit month, and two-digit day. | `"yyyyMMdd"
"20190323"` **Times** | -`basic_time`
A time with a two-digit hour, two-digit minute, two-digit second, three-digit millisecond, and time zone offset. |"HHmmss.SSSZ"
"213446.123-04:00" -`basic_time_no_millis`
A basic time without milliseconds. | "HHmmssZ"
"213446-04:00" +`basic_time`
A time with a two-digit hour, two-digit minute, two-digit second, three-digit millisecond, and time zone offset. |`"HHmmss.SSSZ"`
`"213446.123-04:00"` +`basic_time_no_millis`
A basic time without milliseconds. | `"HHmmssZ"`
`"213446-04:00"` **T times** | -`basic_t_time`
A basic time preceded by `T`. | "`T`HHmmss.SSSZ"
"T213446.123-04:00" -`basic_t_time_no_millis`
A basic time without milliseconds, preceded by `T`. | "`T`HHmmssZ"
"T213446-04:00" +`basic_t_time`
A basic time preceded by `T`. | `"`T`HHmmss.SSSZ"`
`"T213446.123-04:00"` +`basic_t_time_no_millis`
A basic time without milliseconds, preceded by `T`. | `"`T`HHmmssZ"`
`"T213446-04:00"` **Ordinal dates** | -`basic_ordinal_date_time`
A full ordinal date and time. | "yyyyDDD`T`HHmmss.SSSZ"
"2019082T213446.123-04:00" -`basic_ordinal_date_time_no_millis`
A full ordinal date and time without milliseconds. | "yyyyDDD`T`HHmmssZ"
"2019082T213446-04:00" -`basic_ordinal_date`
A date with a four-digit year and three-digit ordinal day of the year. | "yyyyDDD"
"2019082" +`basic_ordinal_date_time`
A full ordinal date and time. | `"yyyyDDD`T`HHmmss.SSSZ"`
`"2019082T213446.123-04:00"` +`basic_ordinal_date_time_no_millis`
A full ordinal date and time without milliseconds. | `"yyyyDDD`T`HHmmssZ"`
`"2019082T213446-04:00"` +`basic_ordinal_date`
A date with a four-digit year and three-digit ordinal day of the year. | `"yyyyDDD"`
`"2019082"` **Week-based dates** | -`basic_week_date_time`
`strict_basic_week_date_time`
A full week-based date and time separated by `T`. | "YYYY`W`wwe`T`HHmmss.SSSZ"
"2019W126213446.123-04:00" -`basic_week_date_time_no_millis`
`strict_basic_week_date_time_no_millis`
A basic week-based year date and time without milliseconds, separated by `T`. | "YYYY`W`wwe`T`HHmmssZ"
"2019W126213446-04:00" -`basic_week_date`
`strict_basic_week_date`
A full week-based date with a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week separated by `W`. | "YYYY`W`wwe"
"2019W126" +`basic_week_date_time`
`strict_basic_week_date_time`
A full week-based date and time separated by `T`. | `"YYYY`W`wwe`T`HHmmss.SSSZ"`
`"2019W126213446.123-04:00"` +`basic_week_date_time_no_millis`
`strict_basic_week_date_time_no_millis`
A basic week-based year date and time without milliseconds, separated by `T`. | `"YYYY`W`wwe`T`HHmmssZ"`
"2019W126213446-04:00" +`basic_week_date`
`strict_basic_week_date`
A full week-based date with a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week separated by `W`. | `"YYYY`W`wwe"`
`"2019W126"` ### Full date formats -Components of full date formats are separated by a `-` delimiter for date and `:` delimiter for time. For example, "2019-03-23T21:34". +Components of full date formats are separated by a `-` delimiter for date and `:` delimiter for time. For example, `"2019-03-23T21:34"`. Format name and description | Pattern and examples :--- | :--- **Dates** | -`date_optional_time`
`strict_date_optional_time`
A generic full date and time. Year is required. Month, day, and time are optional. Time is separated from date by `T`. | Multiple patterns.
"2019-03-23T21:34:46.123456789-04:00"
"2019-03-23T21:34:46"
"2019-03-23T21:34"
"2019" -`strict_date_optional_time_nanos`
A generic full date and time. Year is required. Month, day, and time are optional. If time is specified, it must contain hours, minutes, and seconds, but fraction of a second is optional. Fraction of a second is one to nine digits long and has nanosecond resolution. Time is separated from date by `T`. | Multiple patterns.
"2019-03-23T21:34:46.123456789-04:00"
"2019-03-23T21:34:46"
"2019" -`date_time`
`strict_date_time`
A full date and time separated by `T`. | "yyyy-MM-dd`T`HH:mm:ss.SSSZ"
"2019-03-23T21:34:46.123-04:00" -`date_time_no_millis`
`strict_date_time_no_millis`
A full date and time without milliseconds, separated by `T`. | "yyyy-MM-dd'T'HH:mm:ssZ"
"2019-03-23T21:34:46-04:00" -`date_hour_minute_second_fraction`
`strict_date_hour_minute_second_fraction`
A full date, two-digit hour, two-digit minute, two-digit second, and one- to nine-digit fraction of a second separated by `T`. | "yyyy-MM-dd`T`HH:mm:ss.SSSSSSSSS"
"2019-03-23T21:34:46.123456789"
"2019-03-23T21:34:46.1" -`date_hour_minute_second_millis`
`strict_date_hour_minute_second_millis`
A full date, two-digit hour, two-digit minute, two-digit second, and three-digit millisecond separated by `T`. | "yyyy-MM-dd`T`HH:mm:ss.SSS"
"2019-03-23T21:34:46.123" -`date_hour_minute_second`
`strict_date_hour_minute_second`
A full date, two-digit hour, two-digit minute, and two-digit second separated by `T`.| "yyyy-MM-dd`T`HH:mm:ss"
"2019-03-23T21:34:46" -`date_hour_minute`
`strict_date_hour_minute`
A full date, two-digit hour, and two-digit minute. | "yyyy-MM-dd`T`HH:mm"
"2019-03-23T21:34" -`date_hour`
`strict_date_hour`
A full date and two-digit hour, separated by `T`. | "yyyy-MM-dd`T`HH"
"2019-03-23T21" -`date`
`strict_date`
A four-digit year, two-digit month, and two-digit day. | "yyyy-MM-dd"
"2019-03-23" -`year_month_day`
`strict_year_month_day`
A four-digit year, two-digit month, and two-digit day. | "yyyy-MM-dd"
"2019-03-23" -`year_month`
`strict_year_month`
A four-digit year and two-digit month. | "yyyy-MM"
"2019-03" -`year`
`strict_year`
A four-digit year. | "yyyy"
"2019" +`date_optional_time`
`strict_date_optional_time`
A generic full date and time. Year is required. Month, day, and time are optional. Time is separated from date by `T`. | Multiple patterns.
`"2019--03--23T21:34:46.123456789--04:00"`
`"2019-03-23T21:34:46"`
`"2019-03-23T21:34"`
`"2019"` +`strict_date_optional_time_nanos`
A generic full date and time. Year is required. Month, day, and time are optional. If time is specified, it must contain hours, minutes, and seconds, but fraction of a second is optional. Fraction of a second is one to nine digits long and has nanosecond resolution. Time is separated from date by `T`. | Multiple patterns.
`"2019-03-23T21:34:46.123456789-04:00"`
`"2019-03-23T21:34:46"`
`"2019"` +`date_time`
`strict_date_time`
A full date and time separated by `T`. | `"yyyy-MM-dd`T`HH:mm:ss.SSSZ"`
`"2019-03-23T21:34:46.123-04:00"` +`date_time_no_millis`
`strict_date_time_no_millis`
A full date and time without milliseconds, separated by `T`. | `"yyyy-MM-dd'T'HH:mm:ssZ"`
`"2019-03-23T21:34:46-04:00"` +`date_hour_minute_second_fraction`
`strict_date_hour_minute_second_fraction`
A full date, two-digit hour, two-digit minute, two-digit second, and one- to nine-digit fraction of a second separated by `T`. | `"yyyy-MM-dd`T`HH:mm:ss.SSSSSSSSS"`
`"2019-03-23T21:34:46.123456789"`
`"2019-03-23T21:34:46.1"` +`date_hour_minute_second_millis`
`strict_date_hour_minute_second_millis`
A full date, two-digit hour, two-digit minute, two-digit second, and three-digit millisecond separated by `T`. | `"yyyy-MM-dd`T`HH:mm:ss.SSS"`
`"2019-03-23T21:34:46.123"` +`date_hour_minute_second`
`strict_date_hour_minute_second`
A full date, two-digit hour, two-digit minute, and two-digit second separated by `T`.| `"yyyy-MM-dd`T`HH:mm:ss"`
`"2019-03-23T21:34:46"` +`date_hour_minute`
`strict_date_hour_minute`
A full date, two-digit hour, and two-digit minute. | `"yyyy-MM-dd`T`HH:mm"`
`"2019-03-23T21:34"` +`date_hour`
`strict_date_hour`
A full date and two-digit hour, separated by `T`. | `"yyyy-MM-dd`T`HH"`
`"2019-03-23T21"` +`date`
`strict_date`
A four-digit year, two-digit month, and two-digit day. | `"yyyy-MM-dd"`
`"2019-03-23"` +`year_month_day`
`strict_year_month_day`
A four-digit year, two-digit month, and two-digit day. | `"yyyy-MM-dd"`
`"2019-03-23"` +`year_month`
`strict_year_month`
A four-digit year and two-digit month. | `"yyyy-MM"`
`"2019-03"` +`year`
`strict_year`
A four-digit year. | `"yyyy"`
`"2019"` +`rfc3339_lenient`
An RFC3339 compatible DateTimeFormatter which is much faster than other full date-lenient formats like `strict_date_optional_time` | `"YYYY"`
`"2019"`
`"YYYY-MM"`
`"2019-03"`
`"YYYY-MM-DD"`
`"2019-03-23"`
`"YYYY-MM-DDThh:mmTZD"`
`"2019-03-23T21:34Z"`
`"YYYY-MM-DDThh:mm:ssTZD"`
`"2019-03-23T21:34:46Z"`
`"YYYY-MM-DDThh:mm:ss.sTZD"`
`"2019-03-23T21:34:46.123456789-04:00"`
`"YYYY-MM-DDThh:mm:ss,sTZD"`
`"2019-03-23T21:34:46,123456789-04:00"` **Times** | -`time`
`strict_time`
A two-digit hour, two-digit minute, two-digit second, one- to nine-digit fraction of a second, and time zone offset. | "HH:mm:ss.SSSSSSSSSZ"
"21:34:46.123456789-04:00"
"21:34:46.1-04:00" -`time_no_millis`
`strict_time_no_millis`
A two-digit hour, two-digit minute, two-digit second, and time zone offset. | "HH:mm:ssZ"
"21:34:46-04:00" -`hour_minute_second_fraction`
`strict_hour_minute_second_fraction`
A two-digit hour, two-digit minute, two-digit second, and one- to nine-digit fraction of a second. | "HH:mm:ss.SSSSSSSSS"
"21:34:46.1"
"21:34:46.123456789" -`hour_minute_second_millis`
`strict_hour_minute_second_millis`
A two-digit hour, two-digit minute, two-digit second, and three-digit millisecond. | "HH:mm:ss.SSS"
"21:34:46.123" -`hour_minute_second`
`strict_hour_minute_second`
A two-digit hour, two-digit minute, and two-digit second. | "HH:mm:ss"
"21:34:46" -`hour_minute`
`strict_hour_minute`
A two-digit hour and two-digit minute. | "HH:mm"
"21:34" -`hour`
`strict_hour`
A two-digit hour. | "HH"
"21" +`time`
`strict_time`
A two-digit hour, two-digit minute, two-digit second, one- to nine-digit fraction of a second, and time zone offset. | `"HH:mm:ss.SSSSSSSSSZ"`
`"21:34:46.123456789-04:00"`
`"21:34:46.1-04:00"` +`time_no_millis`
`strict_time_no_millis`
A two-digit hour, two-digit minute, two-digit second, and time zone offset. | `"HH:mm:ssZ"`
`"21:34:46-04:00"` +`hour_minute_second_fraction`
`strict_hour_minute_second_fraction`
A two-digit hour, two-digit minute, two-digit second, and one- to nine-digit fraction of a second. | `"HH:mm:ss.SSSSSSSSS"`
`"21:34:46.1"`
`"21:34:46.123456789"` +`hour_minute_second_millis`
`strict_hour_minute_second_millis`
A two-digit hour, two-digit minute, two-digit second, and three-digit millisecond. | `"HH:mm:ss.SSS"`
`"21:34:46.123"` +`hour_minute_second`
`strict_hour_minute_second`
A two-digit hour, two-digit minute, and two-digit second. | `"HH:mm:ss"`
`"21:34:46"` +`hour_minute`
`strict_hour_minute`
A two-digit hour and two-digit minute. | `"HH:mm"`
`"21:34"` +`hour`
`strict_hour`
A two-digit hour. | `"HH"`
`"21"` **T times** | -`t_time`
`strict_t_time`
A two-digit hour, two-digit minute, two-digit second, one- to nine-digit fraction of a second, and time zone offset, preceded by `T`. | "`T`HH:mm:ss.SSSSSSSSSZ"
"T21:34:46.123456789-04:00"
"T21:34:46.1-04:00" -`t_time_no_millis`
`strict_t_time_no_millis`
A two-digit hour, two-digit minute, two-digit second, and time zone offset, preceded by `T`. | "`T`HH:mm:ssZ"
"T21:34:46-04:00" +`t_time`
`strict_t_time`
A two-digit hour, two-digit minute, two-digit second, one- to nine-digit fraction of a second, and time zone offset, preceded by `T`. | `"`T`HH:mm:ss.SSSSSSSSSZ"
"T21:34:46.123456789-04:00"`
`"T21:34:46.1-04:00"` +`t_time_no_millis`
`strict_t_time_no_millis`
A two-digit hour, two-digit minute, two-digit second, and time zone offset, preceded by `T`. | `"`T`HH:mm:ssZ"`
`"T21:34:46-04:00"` **Ordinal dates** | -`ordinal_date_time`
`strict_ordinal_date_time`
A full ordinal date and time separated by `T`. | "yyyy-DDD`T`HH:mm:ss.SSSZ"
"2019-082T21:34:46.123-04:00" -`ordinal_date_time_no_millis`
`strict_ordinal_date_time_no_millis`
A full ordinal date and time without milliseconds, separated by `T`. | "yyyy-DDD`T`HH:mm:ssZ"
"2019-082T21:34:46-04:00" -`ordinal_date`
`strict_ordinal_date`
A full ordinal date with a four-digit year and three-digit ordinal day of the year. | "yyyy-DDD"
"2019-082" +`ordinal_date_time`
`strict_ordinal_date_time`
A full ordinal date and time separated by `T`. | `"yyyy-DDD`T`HH:mm:ss.SSSZ"`
`"2019-082T21:34:46.123-04:00"` +`ordinal_date_time_no_millis`
`strict_ordinal_date_time_no_millis`
A full ordinal date and time without milliseconds, separated by `T`. | `"yyyy-DDD`T`HH:mm:ssZ"`
`"2019-082T21:34:46-04:00"` +`ordinal_date`
`strict_ordinal_date`
A full ordinal date with a four-digit year and three-digit ordinal day of the year. | `"yyyy-DDD"`
`"2019-082"` **Week-based dates** | -`week_date_time`
`strict_week_date_time`
A full week-based date and time separated by `T`. Week date is a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week. Time is a two-digit hour, two-digit minute, two-digit second, one- to nine-digit fraction of a second, and a time zone offset. | "YYYY-`W`ww-e`T`HH:mm:ss.SSSSSSSSSZ"
"2019-W12-6T21:34:46.1-04:00"
"2019-W12-6T21:34:46.123456789-04:00" -`week_date_time_no_millis`
`strict_week_date_time_no_millis`
A full week-based date and time without milliseconds, separated by `T`. Week date is a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week. Time is a two-digit hour, two-digit minute, two-digit second, and time zone offset. | "YYYY-`W`ww-e`T`HH:mm:ssZ"
"2019-W12-6T21:34:46-04:00" -`week_date`
`strict_week_date`
A full week-based date with a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week. | "YYYY-`W`ww-e"
"2019-W12-6" -`weekyear_week_day`
`strict_weekyear_week_day`
A four-digit week-based year, two-digit ordinal week of the year, and one digit day of the week. | "YYYY-'W'ww-e"
"2019-W12-6" -`weekyear_week`
`strict_weekyear_week`
A four-digit week-based year and two-digit ordinal week of the year. | "YYYY-`W`ww"
"2019-W12" -`weekyear`
`strict_weekyear`
A four-digit week-based year. | "YYYY"
"2019" +`week_date_time`
`strict_week_date_time`
A full week-based date and time separated by `T`. Week date is a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week. Time is a two-digit hour, two-digit minute, two-digit second, one- to nine-digit fraction of a second, and a time zone offset. | `"YYYY-`W`ww-e`T`HH:mm:ss.SSSSSSSSSZ"`
`"2019-W12-6T21:34:46.1-04:00"`
`"2019-W12-6T21:34:46.123456789-04:00"` +`week_date_time_no_millis`
`strict_week_date_time_no_millis`
A full week-based date and time without milliseconds, separated by `T`. Week date is a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week. Time is a two-digit hour, two-digit minute, two-digit second, and time zone offset. | `"YYYY-`W`ww-e`T`HH:mm:ssZ"`
`"2019-W12-6T21:34:46-04:00"` +`week_date`
`strict_week_date`
A full week-based date with a four-digit week-based year, two-digit ordinal week of the year, and one-digit ordinal day of the week. | `"YYYY-`W`ww-e"`
`"2019-W12-6"` +`weekyear_week_day`
`strict_weekyear_week_day`
A four-digit week-based year, two-digit ordinal week of the year, and one digit day of the week. | `"YYYY-'W'ww-e"`
`"2019-W12-6"` +`weekyear_week`
`strict_weekyear_week`
A four-digit week-based year and two-digit ordinal week of the year. | `"YYYY-`W`ww"`
`"2019-W12"` +`weekyear`
`strict_weekyear`
A four-digit week-based year. | `"YYYY"`
`"2019"` ## Custom formats -You can create custom formats for date fields. For example, the following request specifies a date in the common "MM/dd/yyyy" format: +You can create custom formats for date fields. For example, the following request specifies a date in the common `"MM/dd/yyyy"` format: ```json PUT testindex @@ -257,9 +258,9 @@ Date math supports the following time units: The following example expressions illustrate using date math: - `now+1M`: The current date and time in milliseconds since the epoch, plus 1 month. -- `2022-05-18||/M`: 05/18/2022, rounded to the beginning of the month. Resolves to `2022-05-01`. -- `2022-05-18T15:23||/h`: 15:23 on 05/18/2022, rounded to the beginning of the hour. Resolves to `2022-05-18T15`. -- `2022-05-18T15:23:17.789||+2M-1d/d`: 15:23:17.789 on 05/18/2022 plus 2 months minus 1 day, rounded to the beginning of the day. Resolves to `2022-07-17`. +- `2022-05-18||/M`: `05/18/2022`, rounded to the beginning of the month. Resolves to `2022-05-01`. +- `2022-05-18T15:23||/h`: `15:23` on `05/18/2022`, rounded to the beginning of the hour. Resolves to `2022-05-18T15`. +- `2022-05-18T15:23:17.789||+2M-1d/d`: `15:23:17.789` on `05/18/2022` plus 2 months minus 1 day, rounded to the beginning of the day. Resolves to `2022-07-17`. ### Using date math in a range query @@ -300,7 +301,7 @@ PUT testindex/_doc/2 ``` {% include copy-curl.html %} -The following query searches for documents with `release_date` within 2 months and 1 day of 09/14/2022. The lower boundary of the range is rounded to the beginning of the day on 09/14/2022: +The following query searches for documents with `release_date` within 2 months and 1 day of `09/14/2022`. The lower boundary of the range is rounded to the beginning of the day on `09/14/2022`: ```json GET testindex/_search @@ -355,4 +356,4 @@ The response contains both documents: ] } } -``` \ No newline at end of file +```