date-format.asciidoc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. [float]
  34. [[built-in]]
  35. === Built In Formats
  36. The following tables lists all the defaults ISO formats supported:
  37. [cols="<,<",options="header",]
  38. |=======================================================================
  39. |Name |Description
  40. |`basic_date`|A basic formatter for a full date as four digit year, two
  41. digit month of year, and two digit day of month (yyyyMMdd).
  42. |`basic_date_time`|A basic formatter that combines a basic date and time,
  43. separated by a 'T' (yyyyMMdd'T'HHmmss.SSSZ).
  44. |`basic_date_time_no_millis`|A basic formatter that combines a basic date
  45. and time without millis, separated by a 'T' (yyyyMMdd'T'HHmmssZ).
  46. |`basic_ordinal_date`|A formatter for a full ordinal date, using a four
  47. digit year and three digit dayOfYear (yyyyDDD).
  48. |`basic_ordinal_date_time`|A formatter for a full ordinal date and time,
  49. using a four digit year and three digit dayOfYear
  50. (yyyyDDD'T'HHmmss.SSSZ).
  51. |`basic_ordinal_date_time_no_millis`|A formatter for a full ordinal date
  52. and time without millis, using a four digit year and three digit
  53. dayOfYear (yyyyDDD'T'HHmmssZ).
  54. |`basic_time`|A basic formatter for a two digit hour of day, two digit
  55. minute of hour, two digit second of minute, three digit millis, and time
  56. zone offset (HHmmss.SSSZ).
  57. |`basic_time_no_millis`|A basic formatter for a two digit hour of day,
  58. two digit minute of hour, two digit second of minute, and time zone
  59. offset (HHmmssZ).
  60. |`basic_t_time`|A basic formatter for a two digit hour of day, two digit
  61. minute of hour, two digit second of minute, three digit millis, and time
  62. zone off set prefixed by 'T' ('T'HHmmss.SSSZ).
  63. |`basic_t_time_no_millis`|A basic formatter for a two digit hour of day,
  64. two digit minute of hour, two digit second of minute, and time zone
  65. offset prefixed by 'T' ('T'HHmmssZ).
  66. |`basic_week_date`|A basic formatter for a full date as four digit
  67. weekyear, two digit week of weekyear, and one digit day of week
  68. (xxxx'W'wwe).
  69. |`basic_week_date_time`|A basic formatter that combines a basic weekyear
  70. date and time, separated by a 'T' (xxxx'W'wwe'T'HHmmss.SSSZ).
  71. |`basic_week_date_time_no_millis`|A basic formatter that combines a basic
  72. weekyear date and time without millis, separated by a 'T'
  73. (xxxx'W'wwe'T'HHmmssZ).
  74. |`date`|A formatter for a full date as four digit year, two digit month
  75. of year, and two digit day of month (yyyy-MM-dd).
  76. |`date_hour`|A formatter that combines a full date and two digit hour of
  77. day.
  78. |`date_hour_minute`|A formatter that combines a full date, two digit hour
  79. of day, and two digit minute of hour.
  80. |`date_hour_minute_second`|A formatter that combines a full date, two
  81. digit hour of day, two digit minute of hour, and two digit second of
  82. minute.
  83. |`date_hour_minute_second_fraction`|A formatter that combines a full
  84. date, two digit hour of day, two digit minute of hour, two digit second
  85. of minute, and three digit fraction of second
  86. (yyyy-MM-dd'T'HH:mm:ss.SSS).
  87. |`date_hour_minute_second_millis`|A formatter that combines a full date,
  88. two digit hour of day, two digit minute of hour, two digit second of
  89. minute, and three digit fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS).
  90. |`date_optional_time`|a generic ISO datetime parser where the date is
  91. mandatory and the time is optional.
  92. |`date_time`|A formatter that combines a full date and time, separated by
  93. a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).
  94. |`date_time_no_millis`|A formatter that combines a full date and time
  95. without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ).
  96. |`hour`|A formatter for a two digit hour of day.
  97. |`hour_minute`|A formatter for a two digit hour of day and two digit
  98. minute of hour.
  99. |`hour_minute_second`|A formatter for a two digit hour of day, two digit
  100. minute of hour, and two digit second of minute.
  101. |`hour_minute_second_fraction`|A formatter for a two digit hour of day,
  102. two digit minute of hour, two digit second of minute, and three digit
  103. fraction of second (HH:mm:ss.SSS).
  104. |`hour_minute_second_millis`|A formatter for a two digit hour of day, two
  105. digit minute of hour, two digit second of minute, and three digit
  106. fraction of second (HH:mm:ss.SSS).
  107. |`ordinal_date`|A formatter for a full ordinal date, using a four digit
  108. year and three digit dayOfYear (yyyy-DDD).
  109. |`ordinal_date_time`|A formatter for a full ordinal date and time, using
  110. a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ss.SSSZZ).
  111. |`ordinal_date_time_no_millis`|A formatter for a full ordinal date and
  112. time without millis, using a four digit year and three digit dayOfYear
  113. (yyyy-DDD'T'HH:mm:ssZZ).
  114. |`time`|A formatter for a two digit hour of day, two digit minute of
  115. hour, two digit second of minute, three digit fraction of second, and
  116. time zone offset (HH:mm:ss.SSSZZ).
  117. |`time_no_millis`|A formatter for a two digit hour of day, two digit
  118. minute of hour, two digit second of minute, and time zone offset
  119. (HH:mm:ssZZ).
  120. |`t_time`|A formatter for a two digit hour of day, two digit minute of
  121. hour, two digit second of minute, three digit fraction of second, and
  122. time zone offset prefixed by 'T' ('T'HH:mm:ss.SSSZZ).
  123. |`t_time_no_millis`|A formatter for a two digit hour of day, two digit
  124. minute of hour, two digit second of minute, and time zone offset
  125. prefixed by 'T' ('T'HH:mm:ssZZ).
  126. |`week_date`|A formatter for a full date as four digit weekyear, two
  127. digit week of weekyear, and one digit day of week (xxxx-'W'ww-e).
  128. |`week_date_time`|A formatter that combines a full weekyear date and
  129. time, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ).
  130. |`weekDateTimeNoMillis`|A formatter that combines a full weekyear date
  131. and time without millis, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ssZZ).
  132. |`week_year`|A formatter for a four digit weekyear.
  133. |`weekyearWeek`|A formatter for a four digit weekyear and two digit week
  134. of weekyear.
  135. |`weekyearWeekDay`|A formatter for a four digit weekyear, two digit week
  136. of weekyear, and one digit day of week.
  137. |`year`|A formatter for a four digit year.
  138. |`year_month`|A formatter for a four digit year and two digit month of
  139. year.
  140. |`year_month_day`|A formatter for a four digit year, two digit month of
  141. year, and two digit day of month.
  142. |=======================================================================
  143. [float]
  144. [[custom]]
  145. === Custom Format
  146. Allows for a completely customizable date format explained
  147. http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html[here].