0
0
Elasticsearchquery~20 mins

Range buckets in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Range Buckets Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple range bucket aggregation
What is the output of this Elasticsearch aggregation query on the field price with the given buckets?
Elasticsearch
{
  "aggs": {
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 50 },
          { "from": 50, "to": 100 },
          { "from": 100 }
        ]
      }
    }
  }
}
A{"aggregations":{"price_ranges":{"buckets":[{"key":"*-50.0","to":50.0,"doc_count":5},{"key":"50.0-100.0","from":50.0,"to":100.0,"doc_count":3},{"key":"100.0-*","from":100.0,"doc_count":2}]}}}
B{"aggregations":{"price_ranges":{"buckets":[{"key":"*-50.0","to":50.0,"doc_count":3},{"key":"50.0-100.0","from":50.0,"to":100.0,"doc_count":5},{"key":"100.0-*","from":100.0,"doc_count":2}]}}}
C{"aggregations":{"price_ranges":{"buckets":[{"key":"*-50.0","to":50.0,"doc_count":2},{"key":"50.0-100.0","from":50.0,"to":100.0,"doc_count":3},{"key":"100.0-*","from":100.0,"doc_count":5}]}}}
D{"aggregations":{"price_ranges":{"buckets":[{"key":"*-50.0","to":50.0,"doc_count":4},{"key":"50.0-100.0","from":50.0,"to":100.0,"doc_count":4},{"key":"100.0-*","from":100.0,"doc_count":2}]}}}
Attempts:
2 left
💡 Hint
Look carefully at how documents are counted in each price range bucket.
🧠 Conceptual
intermediate
1:30remaining
Understanding range bucket keys
In Elasticsearch range bucket aggregations, what does the bucket key "* - 100.0" represent?
AAll documents with values less than 100
BAll documents with values between 0 and 100
CAll documents with values exactly equal to 100
DAll documents with values greater than 100
Attempts:
2 left
💡 Hint
The asterisk (*) means unbounded on one side.
🔧 Debug
advanced
2:00remaining
Identify the error in this range bucket aggregation
This aggregation query is intended to create two buckets: prices less than 20 and prices between 20 and 50. What error will Elasticsearch return?
Elasticsearch
{
  "aggs": {
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 20 },
          { "from": 20, "to": 50 },
          { "from": 50, "to": 10 }
        ]
      }
    }
  }
}
AElasticsearch returns a syntax error due to missing commas
BElasticsearch returns a validation error because the last range has from > to
CElasticsearch returns no error and processes all buckets correctly
DElasticsearch returns an error because the field "price" does not exist
Attempts:
2 left
💡 Hint
Check the order of from and to values in each range.
📝 Syntax
advanced
1:30remaining
Which option correctly defines a range bucket aggregation with open-ended ranges?
Select the correct JSON snippet for an Elasticsearch range aggregation with these buckets: less than 30, 30 to 70, and greater than 70.
A{ "range": { "field": "age", "ranges": [ { "to": 30 }, { "from": 30, "to": 70 }, { "to": 70, "from": 70 } ] } }
B{ "range": { "field": "age", "ranges": [ { "from": 0, "to": 30 }, { "from": 30, "to": 70 }, { "to": 70 } ] } }
C{ "range": { "field": "age", "ranges": [ { "to": 30 }, { "from": 30, "to": 70 }, { "from": 70 } ] } }
D{ "range": { "field": "age", "ranges": [ { "to": 30 }, { "from": 30, "to": 70 }, { "from": 70, "to": 100 } ] } }
Attempts:
2 left
💡 Hint
Open-ended ranges omit either from or to.
🚀 Application
expert
3:00remaining
Calculate total documents in overlapping range buckets
Given this range aggregation with overlapping buckets, what is the total number of documents counted across all buckets if the index has 10 documents with these price values: [10, 25, 40, 55, 60, 75, 80, 90, 110, 130]? Aggregation: { "aggs": { "price_ranges": { "range": { "field": "price", "ranges": [ { "to": 50 }, { "from": 30, "to": 70 }, { "from": 60 } ] } } } }
A15
B10
C13
D12
Attempts:
2 left
💡 Hint
Count how many documents fall into each bucket, then sum all counts.