ES|QL DATE_EXTRACT function
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
Extracts parts of a date, like year, month, day, hour.
datePart- Part of the date to extract. Can be:
aligned_day_of_week_in_month,aligned_day_of_week_in_year,aligned_week_of_month,aligned_week_of_year,ampm_of_day,clock_hour_of_ampm,clock_hour_of_day,day_of_month,day_of_week,day_of_year,epoch_day,era,hour_of_ampm,hour_of_day,instant_seconds,micro_of_day,micro_of_second,milli_of_day,milli_of_second,minute_of_day,minute_of_hour,month_of_year,nano_of_day,nano_of_second,offset_seconds,proleptic_month,second_of_day,second_of_minute,year, oryear_of_era. Refer to java.time.temporal.ChronoField for a description of these values. Ifnull, the function returnsnull. date-
Date expression. If
null, the function returnsnull.
Extracts parts of a date, like year, month, day, hour.
| datePart | date | result |
|---|---|---|
| keyword | date | long |
| keyword | date_nanos | long |
| text | date | long |
| text | date_nanos | long |
ROW date = DATE_PARSE("yyyy-MM-dd", "2022-05-06")
| EVAL year = DATE_EXTRACT("year", date)
| date:date | year:long |
|---|---|
| 2022-05-06T00:00:00.000Z | 2022 |
Find all events that occurred outside of business hours (before 9 AM or after 5PM), on any given date:
FROM sample_data
| WHERE DATE_EXTRACT("hour_of_day", @timestamp) < 9
AND DATE_EXTRACT("hour_of_day", @timestamp) >= 17
| @timestamp:date | client_ip:ip | event_duration:long | message:keyword |
|---|