date-format.asciidoc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. [[mapping-date-format]]
  2. == Date Format
  3. In JSON documents, dates are represented as strings. Elasticsearch uses a set
  4. of pre-configured format to recognize and convert those, but you can change the
  5. defaults by specifying the `format` option when defining a `date` type, or by
  6. specifying `dynamic_date_formats` in the `root object` mapping (which will
  7. be used unless explicitly overridden by a `date` type). There are built in
  8. formats supported, as well as complete custom one.
  9. The parsing of dates uses http://joda-time.sourceforge.net/[Joda]. The
  10. default date parsing used if no format is specified is
  11. http://joda-time.sourceforge.net/api-release/org/joda/time/format/ISODateTimeFormat.html#dateOptionalTimeParser[ISODateTimeFormat.dateOptionalTimeParser]().
  12. An extension to the format allow to define several formats using `||`
  13. separator. This allows to define less strict formats that can be used,
  14. for example, the `yyyy/MM/dd HH:mm:ss||yyyy/MM/dd` format will parse
  15. both `yyyy/MM/dd HH:mm:ss` and `yyyy/MM/dd`. The first format will also
  16. act as the one that converts back from milliseconds to a string
  17. representation.
  18. [float]
  19. [[date-math]]
  20. === Date Math
  21. The `date` type supports using date math expression when using it in a
  22. query/filter (mainly make sense in `range` query/filter).
  23. The expression starts with an "anchor" date, which can be either `now`
  24. or a date string (in the applicable format) ending with `||`. It can
  25. then follow by a math expression, supporting `+`, `-` and `/`
  26. (rounding). The units supported are `y` (year), `M` (month), `w` (week), `h` (hour),
  27. `m` (minute), and `s` (second).
  28. Here are some samples: `now+1h`, `now+1h+1m`, `now+1h/d`,
  29. `2012-01-01||+1M/d`.
  30. Note, when doing `range` type searches, and the upper value is
  31. inclusive, the rounding will properly be rounded to the ceiling instead
  32. of flooring it.
  33. To change this behavior, set
  34. `"mapping.date.round_ceil": false`.
  35. [float]
  36. [[built-in]]
  37. === Built In Formats
  38. The following tables lists all the defaults ISO formats supported:
  39. [cols="<,<",options="header",]
  40. |=======================================================================
  41. |Name |Description
  42. |`basic_date`|A basic formatter for a full date as four digit year, two
  43. digit month of year, and two digit day of month (yyyyMMdd).
  44. |`basic_date_time`|A basic formatter that combines a basic date and time,
  45. separated by a 'T' (yyyyMMdd'T'HHmmss.SSSZ).
  46. |`basic_date_time_no_millis`|A basic formatter that combines a basic date
  47. and time without millis, separated by a 'T' (yyyyMMdd'T'HHmmssZ).
  48. |`basic_ordinal_date`|A formatter for a full ordinal date, using a four
  49. digit year and three digit dayOfYear (yyyyDDD).
  50. |`basic_ordinal_date_time`|A formatter for a full ordinal date and time,
  51. using a four digit year and three digit dayOfYear
  52. (yyyyDDD'T'HHmmss.SSSZ).
  53. |`basic_ordinal_date_time_no_millis`|A formatter for a full ordinal date
  54. and time without millis, using a four digit year and three digit
  55. dayOfYear (yyyyDDD'T'HHmmssZ).
  56. |`basic_time`|A basic formatter for a two digit hour of day, two digit
  57. minute of hour, two digit second of minute, three digit millis, and time
  58. zone offset (HHmmss.SSSZ).
  59. |`basic_time_no_millis`|A basic formatter for a two digit hour of day,
  60. two digit minute of hour, two digit second of minute, and time zone
  61. offset (HHmmssZ).
  62. |`basic_t_time`|A basic formatter for a two digit hour of day, two digit
  63. minute of hour, two digit second of minute, three digit millis, and time
  64. zone off set prefixed by 'T' ('T'HHmmss.SSSZ).
  65. |`basic_t_time_no_millis`|A basic formatter for a two digit hour of day,
  66. two digit minute of hour, two digit second of minute, and time zone
  67. offset prefixed by 'T' ('T'HHmmssZ).
  68. |`basic_week_date`|A basic formatter for a full date as four digit
  69. weekyear, two digit week of weekyear, and one digit day of week
  70. (xxxx'W'wwe).
  71. |`basic_week_date_time`|A basic formatter that combines a basic weekyear
  72. date and time, separated by a 'T' (xxxx'W'wwe'T'HHmmss.SSSZ).
  73. |`basic_week_date_time_no_millis`|A basic formatter that combines a basic
  74. weekyear date and time without millis, separated by a 'T'
  75. (xxxx'W'wwe'T'HHmmssZ).
  76. |`date`|A formatter for a full date as four digit year, two digit month
  77. of year, and two digit day of month (yyyy-MM-dd).
  78. |`date_hour`|A formatter that combines a full date and two digit hour of
  79. day.
  80. |`date_hour_minute`|A formatter that combines a full date, two digit hour
  81. of day, and two digit minute of hour.
  82. |`date_hour_minute_second`|A formatter that combines a full date, two
  83. digit hour of day, two digit minute of hour, and two digit second of
  84. minute.
  85. |`date_hour_minute_second_fraction`|A formatter that combines a full
  86. date, two digit hour of day, two digit minute of hour, two digit second
  87. of minute, and three digit fraction of second
  88. (yyyy-MM-dd'T'HH:mm:ss.SSS).
  89. |`date_hour_minute_second_millis`|A formatter that combines a full date,
  90. two digit hour of day, two digit minute of hour, two digit second of
  91. minute, and three digit fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS).
  92. |`date_optional_time`|a generic ISO datetime parser where the date is
  93. mandatory and the time is optional.
  94. |`date_time`|A formatter that combines a full date and time, separated by
  95. a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).
  96. |`date_time_no_millis`|A formatter that combines a full date and time
  97. without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ).
  98. |`hour`|A formatter for a two digit hour of day.
  99. |`hour_minute`|A formatter for a two digit hour of day and two digit
  100. minute of hour.
  101. |`hour_minute_second`|A formatter for a two digit hour of day, two digit
  102. minute of hour, and two digit second of minute.
  103. |`hour_minute_second_fraction`|A formatter for a two digit hour of day,
  104. two digit minute of hour, two digit second of minute, and three digit
  105. fraction of second (HH:mm:ss.SSS).
  106. |`hour_minute_second_millis`|A formatter for a two digit hour of day, two
  107. digit minute of hour, two digit second of minute, and three digit
  108. fraction of second (HH:mm:ss.SSS).
  109. |`ordinal_date`|A formatter for a full ordinal date, using a four digit
  110. year and three digit dayOfYear (yyyy-DDD).
  111. |`ordinal_date_time`|A formatter for a full ordinal date and time, using
  112. a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ss.SSSZZ).
  113. |`ordinal_date_time_no_millis`|A formatter for a full ordinal date and
  114. time without millis, using a four digit year and three digit dayOfYear
  115. (yyyy-DDD'T'HH:mm:ssZZ).
  116. |`time`|A formatter for a two digit hour of day, two digit minute of
  117. hour, two digit second of minute, three digit fraction of second, and
  118. time zone offset (HH:mm:ss.SSSZZ).
  119. |`time_no_millis`|A formatter for a two digit hour of day, two digit
  120. minute of hour, two digit second of minute, and time zone offset
  121. (HH:mm:ssZZ).
  122. |`t_time`|A formatter for a two digit hour of day, two digit minute of
  123. hour, two digit second of minute, three digit fraction of second, and
  124. time zone offset prefixed by 'T' ('T'HH:mm:ss.SSSZZ).
  125. |`t_time_no_millis`|A formatter for a two digit hour of day, two digit
  126. minute of hour, two digit second of minute, and time zone offset
  127. prefixed by 'T' ('T'HH:mm:ssZZ).
  128. |`week_date`|A formatter for a full date as four digit weekyear, two
  129. digit week of weekyear, and one digit day of week (xxxx-'W'ww-e).
  130. |`week_date_time`|A formatter that combines a full weekyear date and
  131. time, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ).
  132. |`weekDateTimeNoMillis`|A formatter that combines a full weekyear date
  133. and time without millis, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ssZZ).
  134. |`week_year`|A formatter for a four digit weekyear.
  135. |`weekyearWeek`|A formatter for a four digit weekyear and two digit week
  136. of weekyear.
  137. |`weekyearWeekDay`|A formatter for a four digit weekyear, two digit week
  138. of weekyear, and one digit day of week.
  139. |`year`|A formatter for a four digit year.
  140. |`year_month`|A formatter for a four digit year and two digit month of
  141. year.
  142. |`year_month_day`|A formatter for a four digit year, two digit month of
  143. year, and two digit day of month.
  144. |=======================================================================
  145. [float]
  146. [[custom]]
  147. === Custom Format
  148. Allows for a completely customizable date format explained
  149. http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html[here].