0
0
Elasticsearchquery~20 mins

Stats and extended stats in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stats Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of basic stats aggregation
What is the output of this Elasticsearch aggregation query on a dataset with numeric field price containing values [10, 20, 30, 40]?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "price_stats": {
      "stats": {
        "field": "price"
      }
    }
  }
}
A{"aggregations":{"price_stats":{"count":5,"min":10.0,"max":50.0,"avg":30.0,"sum":150.0}}}
B{"aggregations":{"price_stats":{"count":3,"min":10.0,"max":30.0,"avg":20.0,"sum":60.0}}}
C{"aggregations":{"price_stats":{"count":4,"min":10.0,"max":40.0,"avg":25.0,"sum":100.0}}}
D{"aggregations":{"price_stats":{"count":4,"min":10,"max":40,"avg":20,"sum":80}}}
Attempts:
2 left
💡 Hint
Remember that stats aggregation returns count, min, max, avg, and sum for the specified field.
Predict Output
intermediate
2:00remaining
Extended stats aggregation output
Given the following Elasticsearch query on field score with values [5, 7, 9, 11], what is the output of the extended_stats aggregation?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "score_stats": {
      "extended_stats": {
        "field": "score"
      }
    }
  }
}
A{"aggregations":{"score_stats":{"count":4,"min":5.0,"max":11.0,"avg":8.0,"sum":32.0,"sum_of_squares":276.0,"variance":6.666666666666667,"std_deviation":2.581988897471611,"std_deviation_bounds":{"upper":13.581988897471611,"lower":2.418011102528389}}}}
B{"aggregations":{"score_stats":{"count":4,"min":5,"max":11,"avg":8,"sum":32,"sum_of_squares":276,"variance":5,"std_deviation":2.2360679775}}}
C{"aggregations":{"score_stats":{"count":3,"min":5.0,"max":11.0,"avg":7.5,"sum":22.5,"sum_of_squares":150.0,"variance":4.25,"std_deviation":2.0615528128}}}
D{"aggregations":{"score_stats":{"count":4,"min":5.0,"max":11.0,"avg":8.0,"sum":32.0,"sum_of_squares":300.0,"variance":7.0,"std_deviation":2.645751311}}}
Attempts:
2 left
💡 Hint
Extended stats include sum_of_squares, variance, and standard deviation with precise floating point values.
🧠 Conceptual
advanced
1:30remaining
Understanding variance calculation in extended_stats
Which statement correctly describes how Elasticsearch calculates variance in the extended_stats aggregation?
AVariance is calculated by summing the squared values without subtracting the mean first.
BVariance is calculated as the square root of the standard deviation.
CVariance is calculated as the average of squared differences from the mean, dividing by count (population variance).
DVariance is calculated as the average of squared differences from the mean, dividing by count minus one (sample variance).
Attempts:
2 left
💡 Hint
Elasticsearch uses population variance formula in extended_stats aggregation.
Predict Output
advanced
2:00remaining
Output of extended_stats with missing values
What is the output of this extended_stats aggregation on field rating with values [4, null, 6, 8] where null is missing?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "rating_stats": {
      "extended_stats": {
        "field": "rating"
      }
    }
  }
}
A{"aggregations":{"rating_stats":{"count":4,"min":4.0,"max":8.0,"avg":4.5,"sum":18.0,"sum_of_squares":116.0,"variance":2.6666666666666665,"std_deviation":1.632993161855452}}}
B{"aggregations":{"rating_stats":{"count":3,"min":4.0,"max":8.0,"avg":6.0,"sum":18.0,"sum_of_squares":116.0,"variance":2.6666666666666665,"std_deviation":1.632993161855452,"std_deviation_bounds":{"upper":8.632993161855452,"lower":3.367006838144548}}}}
C{"aggregations":{"rating_stats":{"count":3,"min":4,"max":8,"avg":6,"sum":18,"sum_of_squares":100,"variance":3,"std_deviation":1.732}}}
D{"aggregations":{"rating_stats":{"count":4,"min":4,"max":8,"avg":6,"sum":24,"sum_of_squares":116,"variance":2.6666666666666665,"std_deviation":1.632993161855452}}}
Attempts:
2 left
💡 Hint
Null values are ignored in stats aggregations, so count is less than total values.
🔧 Debug
expert
1:30remaining
Identify the error in this extended_stats aggregation query
What error will Elasticsearch return when running this aggregation query?
Elasticsearch
{
  "size": 0,
  "aggs": {
    "stats_error": {
      "extended_stats": {
        "field": "nonexistent_field"
      }
    }
  }
}
ANo error; returns count 0 and all other stats as null or 0.
BElasticsearch throws a <code>FieldNotFoundException</code> error.
CSyntaxError due to missing closing brace.
DRuntime error: division by zero in variance calculation.
Attempts:
2 left
💡 Hint
Elasticsearch handles missing fields gracefully in aggregations.