0
0
Elasticsearchquery~20 mins

Range query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Range Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a basic range query
What is the expected output count of documents matching this Elasticsearch range query on a field age with values from 20 to 30 inclusive?
Elasticsearch
{
  "query": {
    "range": {
      "age": {
        "gte": 20,
        "lte": 30
      }
    }
  }
}
ADocuments with age between 20 and 30 inclusive
BDocuments with age strictly greater than 20 and less than 30
CDocuments with age less than or equal to 30 only
DDocuments with age greater than or equal to 20 only
Attempts:
2 left
💡 Hint
Remember that gte means 'greater than or equal' and lte means 'less than or equal'.
Predict Output
intermediate
2:00remaining
Range query with date format
What documents will match this Elasticsearch range query on a date field?
Elasticsearch
{
  "query": {
    "range": {
      "date": {
        "gte": "2023-01-01",
        "lt": "2023-02-01",
        "format": "yyyy-MM-dd"
      }
    }
  }
}
ADocuments with date from January 1, 2023 inclusive to February 1, 2023 exclusive
Bevisulcxe 3202 ,1 yraurbeF ot evisulcni 3202 ,1 yraunaJ morf etad htiw stnemucoD
CDocuments with date from January 1, 2023 inclusive to January 31, 2023 inclusive, but excluding February 1, 2023
DDocuments with date from January 1, 2023 inclusive to January 31, 2023 inclusive
Attempts:
2 left
💡 Hint
lt means less than, so the upper bound excludes the date specified.
🔧 Debug
advanced
2:00remaining
Identify the error in this range query
What error will this Elasticsearch range query produce?
Elasticsearch
{
  "query": {
    "range": {
      "price": {
        "gte": 100,
        "lte": 200
      }
    }
  }
}
ARuntime error because price field does not exist
BSyntaxError due to missing comma between gte and lte
CNo error, query runs successfully
DTypeError because gte and lte values are not strings
Attempts:
2 left
💡 Hint
Check the JSON syntax carefully between the keys.
🧠 Conceptual
advanced
2:00remaining
Effect of using only lt in a range query
What documents will match this Elasticsearch range query on a field score?
Elasticsearch
{
  "query": {
    "range": {
      "score": {
        "lt": 50
      }
    }
  }
}
ADocuments with score less than or equal to 50
BDocuments with score greater than or equal to 50
CDocuments with score less than 50
DDocuments with score equal to 50 only
Attempts:
2 left
💡 Hint
lt means strictly less than the value.
🚀 Application
expert
3:00remaining
Construct a range query for exclusive bounds
Which Elasticsearch range query matches documents with temperature strictly greater than 10 and strictly less than 20?
A{ "query": { "range": { "temperature": { "gte": 11, "lte": 19 } } } }
B{ "query": { "range": { "temperature": { "gte": 10, "lte": 20 } } } }
C{ "query": { "range": { "temperature": { "gt": 10, "lte": 20 } } } }
D{ "query": { "range": { "temperature": { "gt": 10, "lt": 20 } } } }
Attempts:
2 left
💡 Hint
Use gt and lt for exclusive bounds.