0
0
Elasticsearchquery~20 mins

Date histogram in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Date Histogram Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a basic date histogram aggregation
What is the output of this Elasticsearch aggregation query on an index with documents dated from 2023-01-01 to 2023-01-05, one document per day?
Elasticsearch
{
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "day"
      }
    }
  }
}
A{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-02T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-03T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-04T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-05T00:00:00.000Z","doc_count":1}]}}}
B{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":5}]}}}
C{"aggregations":{"sales_over_time":{"buckets":[]}}}
D{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":0}]}}}
Attempts:
2 left
💡 Hint
Each day has exactly one document, so each day bucket should have doc_count 1.
Predict Output
intermediate
2:00remaining
Effect of missing min_doc_count in date histogram
Given documents on 2023-01-01 and 2023-01-03 only, what buckets will the following date_histogram aggregation return?
Elasticsearch
{
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "day"
      }
    }
  }
}
A{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-03T00:00:00.000Z","doc_count":1}]}}}
B{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-02T00:00:00.000Z","doc_count":0},{"key_as_string":"2023-01-03T00:00:00.000Z","doc_count":1}]}}}
C{"aggregations":{"sales_over_time":{"buckets":[]}}}
D{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-02T00:00:00.000Z","doc_count":0}]}}}
Attempts:
2 left
💡 Hint
By default, buckets with zero documents are not included.
Predict Output
advanced
2:00remaining
Output of date histogram with offset
What is the first bucket key_as_string returned by this aggregation on documents dated 2023-01-01 to 2023-01-05?
Elasticsearch
{
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "day",
        "offset": "+12h"
      }
    }
  }
}
A"2023-01-02T00:00:00.000Z"
B"2023-01-01T00:00:00.000Z"
C"2022-12-31T12:00:00.000Z"
D"2023-01-01T12:00:00.000Z"
Attempts:
2 left
💡 Hint
Offset shifts the bucket boundaries by 12 hours earlier.
Predict Output
advanced
2:00remaining
Result of date histogram with extended_bounds
Given documents only on 2023-01-01 and 2023-01-03, what buckets will this aggregation return?
Elasticsearch
{
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "day",
        "min_doc_count": 0,
        "extended_bounds": {
          "min": "2023-01-01",
          "max": "2023-01-04"
        }
      }
    }
  }
}
A{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-03T00:00:00.000Z","doc_count":1}]}}}
B{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-01T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-02T00:00:00.000Z","doc_count":0},{"key_as_string":"2023-01-03T00:00:00.000Z","doc_count":1},{"key_as_string":"2023-01-04T00:00:00.000Z","doc_count":0}]}}}
C{"aggregations":{"sales_over_time":{"buckets":[]}}}
D{"aggregations":{"sales_over_time":{"buckets":[{"key_as_string":"2023-01-02T00:00:00.000Z","doc_count":0}]}}}
Attempts:
2 left
💡 Hint
extended_bounds forces buckets for all days in the range, even if no documents exist.
🧠 Conceptual
expert
2:00remaining
Understanding time zone effect on date histogram buckets
If you run a date_histogram aggregation with calendar_interval day on a field with UTC timestamps, but set "time_zone": "+02:00", what effect does this have on the bucket boundaries?
ABuckets are shifted 2 hours earlier, so each bucket covers 22 hours instead of 24.
BBuckets remain aligned to UTC days; time_zone only affects display formatting.
CBuckets are shifted 2 hours later, so each bucket covers 24 hours but starts 2 hours later in UTC time.
DBuckets are shifted 2 hours earlier, so each bucket covers 24 hours but starts 2 hours earlier in UTC time.
Attempts:
2 left
💡 Hint
Time zone shifts bucket boundaries relative to UTC time.