<commit_before>[[mapping-date-format]]
== Date Format

In JSON documents, dates are represented as strings. Elasticsearch uses a set
of pre-configured format to recognize and convert those, but you can change the
defaults by specifying the `format` option when defining a `date` type, or by
specifying `dynamic_date_formats` in the `root object` mapping (which will
be used unless explicitly overridden by a `date` type). There are built in
formats supported, as well as complete custom one.

The parsing of dates uses http://joda-time.sourceforge.net/[Joda]. The
default date parsing used if no format is specified is
http://joda-time.sourceforge.net/api-release/org/joda/time/format/ISODateTimeFormat.html#dateOptionalTimeParser()[ISODateTimeFormat.dateOptionalTimeParser].

An extension to the format allow to define several formats using `||`
separator. This allows to define less strict formats that can be used,
for example, the `yyyy/MM/dd HH:mm:ss||yyyy/MM/dd` format will parse
both `yyyy/MM/dd HH:mm:ss` and `yyyy/MM/dd`. The first format will also
act as the one that converts back from milliseconds to a string
representation.

[float]
[[date-math]]
=== Date Math

The `date` type supports using date math expression when using it in a
query/filter (mainly makes sense in `range` query/filter).

The expression starts with an "anchor" date, which can be either `now`
or a date string (in the applicable format) ending with `||`. It can
then follow by a math expression, supporting `+`, `-` and `/`
(rounding). The units supported are `y` (year), `M` (month), `w` (week), `h` (hour),
`m` (minute), and `s` (second).

Here are some samples: `now+1h`, `now+1h+1m`, `now+1h/d`,
`2012-01-01||+1M/d`.<commit_msg>Docs: Added 'd' to the list of supported units.<commit_after>[[mapping-date-format]]
== Date Format

In JSON documents, dates are represented as strings. Elasticsearch uses a set
of pre-configured format to recognize and convert those, but you can change the
defaults by specifying the `format` option when defining a `date` type, or by
specifying `dynamic_date_formats` in the `root object` mapping (which will
be used unless explicitly overridden by a `date` type). There are built in
formats supported, as well as complete custom one.

The parsing of dates uses http://joda-time.sourceforge.net/[Joda]. The
default date parsing used if no format is specified is
http://joda-time.sourceforge.net/api-release/org/joda/time/format/ISODateTimeFormat.html#dateOptionalTimeParser()[ISODateTimeFormat.dateOptionalTimeParser].

An extension to the format allow to define several formats using `||`
separator. This allows to define less strict formats that can be used,
for example, the `yyyy/MM/dd HH:mm:ss||yyyy/MM/dd` format will parse
both `yyyy/MM/dd HH:mm:ss` and `yyyy/MM/dd`. The first format will also
act as the one that converts back from milliseconds to a string
representation.

[float]
[[date-math]]
=== Date Math

The `date` type supports using date math expression when using it in a
query/filter (mainly makes sense in `range` query/filter).

The expression starts with an "anchor" date, which can be either `now`
or a date string (in the applicable format) ending with `||`. It can
then follow by a math expression, supporting `+`, `-` and `/`
(rounding). The units supported are `y` (year), `M` (month), `w` (week),
`d` (day), `h` (hour), `m` (minute), and `s` (second).

Here are some samples: `now+1h`, `now+1h+1m`, `now+1h/d`,
`2012-01-01||+1M/d`.
{'fraction_non_alphanumeric': 0.11174949727089917, 'fraction_numerical': 0.007469118069520253, 'mean_word_length': 4.861952861952862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2390874', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1028, 'n_words': 459}