Executing date histogram facets
The previous recipe works mainly on numeric fields, ElasticSearch provides a custom date histogram facet to operate on date/datetime values.
This facet is required because date values need a deeper customization to solve problems, such as timezone conversion and special time intervals.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script available in online code.
How to do it...
For executing date histogram facets, we will perform the steps given as follows:
We need two different date/time facets, which are:
an annual facet
a quarter facet, but with time zone +1:00
The query will be:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?from=0&pretty=true&size=10' -d ' { "query": { "match_all": {} }, "facets": { "date_year": { "date_histogram": { "field": "date", "interval": "year" } }, "date_quarter": { ...