A date field stores values that Elasticsearch interprets as dates or times. Because dates are structured data, they support filtering, sorting, range queries, and aggregations rather than full-text relevance scoring. section 4.5.3 section 8.9
Define and provide dates consistently:
- Create the field with "type": "date" in the index mapping. section 4.5.3
- Send dates as strings such as 2021-08-06 or 2021-08-06T05:30:00; Elasticsearch parses and indexes them. section 4.5.3
- Customize accepted formats, including alternatives such as dd-MM-yyyy, dd/MM/yyyy, and yyyy-MM-dd. section 4.5.3
- Accept epoch values by mapping dates as epoch_millis or epoch_second; Elasticsearch stores dates internally as millisecond-based long values. section 4.5.3
Find flights within a departure window
A range query can retrieve flights departing between 05:00 and 05:30 on August 6, 2021. The gte and lte bounds define the time window, making the date field useful for operational search. section 4.5.3
Listing 4.17 Creating an index with a date type
PUT flights
{
"mappings": {
"properties": {
"departure_date_time":{
"type": "date"
}
}
}
}
Inspect the mapping that creates departure_date_time as a date field before documents are indexed. section 4.5.3
