- Elasticsearch Guide: other versions:
- Setup
- API Conventions
- Document APIs
- Search APIs
- Indices APIs
- Create Index
- Delete Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Delete Mapping
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Status
- Indices Stats
- Indices Segments
- Clear Cache
- Flush
- Refresh
- Optimize
- Gateway Snapshot
- Cluster APIs
- Query DSL
- Queries
- Match Query
- Multi Match Query
- Bool Query
- Boosting Query
- Common Terms Query
- Custom Filters Score Query
- Custom Score Query
- Custom Boost Factor Query
- Constant Score Query
- Dis Max Query
- Field Query
- Filtered Query
- Fuzzy Like This Query
- Fuzzy Like This Field Query
- Function Score Query
- Fuzzy Query
- GeoShape Query
- Has Child Query
- Has Parent Query
- Ids Query
- Indices Query
- Match All Query
- More Like This Query
- More Like This Field Query
- Nested Query
- Prefix Query
- Query String Query
- Simple Query String Query
- Range Query
- Regexp Query
- Span First Query
- Span Multi Term Query
- Span Near Query
- Span Not Query
- Span Or Query
- Span Term Query
- Term Query
- Terms Query
- Top Children Query
- Wildcard Query
- Text Query
- Minimum Should Match
- Multi Term Query Rewrite
- Filters
- And Filter
- Bool Filter
- Exists Filter
- Geo Bounding Box Filter
- Geo Distance Filter
- Geo Distance Range Filter
- Geo Polygon Filter
- GeoShape Filter
- Geohash Cell Filter
- Has Child Filter
- Has Parent Filter
- Ids Filter
- Indices Filter
- Limit Filter
- Match All Filter
- Missing Filter
- Nested Filter
- Not Filter
- Numeric Range Filter
- Or Filter
- Prefix Filter
- Query Filter
- Range Filter
- Regexp Filter
- Script Filter
- Term Filter
- Terms Filter
- Type Filter
- Queries
- Mapping
- Analysis
- Analyzers
- Tokenizers
- Token Filters
- Standard Token Filter
- ASCII Folding Token Filter
- Length Token Filter
- Lowercase Token Filter
- NGram Token Filter
- Edge NGram Token Filter
- Porter Stem Token Filter
- Shingle Token Filter
- Stop Token Filter
- Word Delimiter Token Filter
- Stemmer Token Filter
- Stemmer Override Token Filter
- Keyword Marker Token Filter
- Keyword Repeat Token Filter
- KStem Token Filter
- Snowball Token Filter
- Phonetic Token Filter
- Synonym Token Filter
- Compound Word Token Filter
- Reverse Token Filter
- Elision Token Filter
- Truncate Token Filter
- Unique Token Filter
- Pattern Capture Token Filter
- Pattern Replace Token Filter
- Trim Token Filter
- Limit Token Count Token Filter
- Hunspell Token Filter
- Common Grams Token Filter
- Normalization Token Filter
- Keep Words Token Filter
- Delimited Payload Token Filter
- Character Filters
- ICU Analysis Plugin
- Modules
- Index Modules
- Glossary of terms
WARNING: Version 0.90 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Date Format
editDate Format
editIn 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 Joda. The default date parsing used if no format is specified is 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.
Date Math
editThe date
type supports using date math expression when using it in a
query/filter (mainly make 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
.
Note, when doing range
type searches, and the upper value is
inclusive, the rounding will properly be rounded to the ceiling instead
of flooring it.
To change this behavior, set
"mapping.date.round_ceil": false
.
Built In Formats
editThe following tables lists all the defaults ISO formats supported:
Name | Description |
---|---|
|
A basic formatter for a full date as four digit year, two digit month of year, and two digit day of month (yyyyMMdd). |
|
A basic formatter that combines a basic date and time, separated by a 'T' (yyyyMMdd'T'HHmmss.SSSZ). |
|
A basic formatter that combines a basic date and time without millis, separated by a 'T' (yyyyMMdd'T'HHmmssZ). |
|
A formatter for a full ordinal date, using a four digit year and three digit dayOfYear (yyyyDDD). |
|
A formatter for a full ordinal date and time, using a four digit year and three digit dayOfYear (yyyyDDD'T'HHmmss.SSSZ). |
|
A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear (yyyyDDD'T'HHmmssZ). |
|
A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit millis, and time zone offset (HHmmss.SSSZ). |
|
A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset (HHmmssZ). |
|
A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit millis, and time zone off set prefixed by 'T' ('T'HHmmss.SSSZ). |
|
A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by 'T' ('T'HHmmssZ). |
|
A basic formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week (xxxx'W'wwe). |
|
A basic formatter that combines a basic weekyear date and time, separated by a 'T' (xxxx'W'wwe'T'HHmmss.SSSZ). |
|
A basic formatter that combines a basic weekyear date and time without millis, separated by a 'T' (xxxx'W'wwe'T'HHmmssZ). |
|
A formatter for a full date as four digit year, two digit month of year, and two digit day of month (yyyy-MM-dd). |
|
A formatter that combines a full date and two digit hour of day. |
|
A formatter that combines a full date, two digit hour of day, and two digit minute of hour. |
|
A formatter that combines a full date, two digit hour of day, two digit minute of hour, and two digit second of minute. |
|
A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS). |
|
A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS). |
|
a generic ISO datetime parser where the date is mandatory and the time is optional. |
|
A formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ). |
|
A formatter that combines a full date and time without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ). |
|
A formatter for a two digit hour of day. |
|
A formatter for a two digit hour of day and two digit minute of hour. |
|
A formatter for a two digit hour of day, two digit minute of hour, and two digit second of minute. |
|
A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second (HH:mm:ss.SSS). |
|
A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second (HH:mm:ss.SSS). |
|
A formatter for a full ordinal date, using a four digit year and three digit dayOfYear (yyyy-DDD). |
|
A formatter for a full ordinal date and time, using a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ss.SSSZZ). |
|
A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ssZZ). |
|
A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and time zone offset (HH:mm:ss.SSSZZ). |
|
A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset (HH:mm:ssZZ). |
|
A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and time zone offset prefixed by 'T' ('T'HH:mm:ss.SSSZZ). |
|
A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by 'T' ('T'HH:mm:ssZZ). |
|
A formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week (xxxx-'W'ww-e). |
|
A formatter that combines a full weekyear date and time, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ). |
|
A formatter that combines a full weekyear date and time without millis, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ssZZ). |
|
A formatter for a four digit weekyear. |
|
A formatter for a four digit weekyear and two digit week of weekyear. |
|
A formatter for a four digit weekyear, two digit week of weekyear, and one digit day of week. |
|
A formatter for a four digit year. |
|
A formatter for a four digit year and two digit month of year. |
|
A formatter for a four digit year, two digit month of year, and two digit day of month. |
Custom Format
editAllows for a completely customizable date format explained here.
On this page