Challenge - 5 Problems
Cardinality Aggregation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this cardinality aggregation query?
Given an Elasticsearch index with documents containing a field
user_id, what will be the value of value in the aggregation result?Elasticsearch
{
"size": 0,
"aggs": {
"unique_users": {
"cardinality": {
"field": "user_id"
}
}
}
}Attempts:
2 left
💡 Hint
Cardinality aggregation counts unique values of a field.
✗ Incorrect
The cardinality aggregation returns the count of distinct values for the specified field, here user_id.
❓ Predict Output
intermediate2:00remaining
What does this cardinality aggregation with precision_threshold do?
Consider this query with
precision_threshold set to 1000. What effect does this have on the cardinality result?Elasticsearch
{
"size": 0,
"aggs": {
"unique_users": {
"cardinality": {
"field": "user_id",
"precision_threshold": 1000
}
}
}
}Attempts:
2 left
💡 Hint
Precision threshold controls accuracy and memory tradeoff.
✗ Incorrect
Setting precision_threshold to 1000 increases accuracy for cardinality counts up to 1000 unique values by using more memory.
🔧 Debug
advanced2:00remaining
Why does this cardinality aggregation return a lower count than expected?
This query returns a cardinality count lower than the actual unique user_id count. What is the most likely cause?
Elasticsearch
{
"size": 0,
"aggs": {
"unique_users": {
"cardinality": {
"field": "user_id",
"precision_threshold": 100
}
}
}
}Attempts:
2 left
💡 Hint
Lower precision_threshold can cause approximate results.
✗ Incorrect
A low precision_threshold reduces memory usage but can cause the cardinality aggregation to underestimate the true count.
🧠 Conceptual
advanced2:00remaining
What is the main tradeoff when using cardinality aggregation in Elasticsearch?
Choose the best description of the tradeoff involved in using cardinality aggregation.
Attempts:
2 left
💡 Hint
Cardinality uses approximate algorithms to save resources.
✗ Incorrect
Cardinality aggregation uses approximate algorithms that trade accuracy for lower memory and CPU usage.
❓ Predict Output
expert2:00remaining
What is the cardinality aggregation result for nested fields?
Given documents with nested field
comments.user_id, which aggregation correctly counts unique user_id values across all comments?Elasticsearch
{
"size": 0,
"aggs": {
"unique_commenters": {
"cardinality": {
"field": "comments.user_id"
}
}
}
}Attempts:
2 left
💡 Hint
Metric aggregations like cardinality work directly on nested fields.
✗ Incorrect
Cardinality aggregation on nested fields correctly counts unique values across all nested objects without requiring a nested wrapper.