0
0
Elasticsearchquery~20 mins

Filter aggregation in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Filter Aggregation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple filter aggregation
What is the output of this Elasticsearch aggregation query when run on an index with documents having a field status with values active and inactive?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "active_users": {
      "filter": {
        "term": { "status": "active" }
      }
    }
  }
}
A{"aggregations":{"active_users":{"doc_count":0}}}
B{"aggregations":{"active_users":{"doc_count":10}}}
C{"aggregations":{"active_users":{"doc_count":5}}}
D{"aggregations":{"active_users":{"doc_count":null}}}
Attempts:
2 left
💡 Hint
The filter aggregation counts documents matching the filter condition.
🧠 Conceptual
intermediate
1:30remaining
Purpose of filter aggregation in Elasticsearch
What is the main purpose of using a filter aggregation in Elasticsearch?
ATo sort documents by a field value in descending order.
BTo count documents matching a specific query condition without affecting other aggregations.
CTo update documents matching a filter condition.
DTo delete documents that do not match the filter.
Attempts:
2 left
💡 Hint
Filter aggregation isolates documents matching a condition for aggregation.
🔧 Debug
advanced
2:00remaining
Identify the error in this filter aggregation query
This filter aggregation query is intended to count documents where age is greater than 30. What error will Elasticsearch return?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "older_than_30": {
      "filter": {
        "range": {
          "age": { "gt": 30 }
        }
      }
    }
  }
}
ANo error, returns count of documents with age > 30.
BQueryParsingException: Unknown key for a START_OBJECT in [range].
CSyntaxError: Missing colon after 'range'.
DTypeError: 'gt' is not a valid operator.
Attempts:
2 left
💡 Hint
Check the syntax of the range filter.
Predict Output
advanced
2:30remaining
Output of nested filter aggregations
Given this aggregation query, what is the value of doc_count for active_and_premium?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "active_users": {
      "filter": { "term": { "status": "active" } },
      "aggs": {
        "active_and_premium": {
          "filter": { "term": { "subscription": "premium" } }
        }
      }
    }
  }
}
A3
B5
C8
D0
Attempts:
2 left
💡 Hint
The inner filter counts documents that are both active and premium.
📝 Syntax
expert
2:00remaining
Which option causes a syntax error in filter aggregation?
Which of these filter aggregation snippets will cause a syntax error when run in Elasticsearch?
A{ "filter": { "term": { "status": "active" } } }
B{ "filter": { "terms": { "status": ["active", "pending"] } } }
C{ "filter": { "range": { "age": { "gte": 18 } } } }
D{ "filter": { "term": { "status" "active" } } }
Attempts:
2 left
💡 Hint
Look for missing punctuation in JSON syntax.