Problem:
Demo multi value metric aggregations: stats and extended stats.
Solution Summary:
Both stats and extended_stats aggregations are multi-value metrics aggregations that computes stats over numeric values extracted from the aggregated documents. These values can be extracted either from specific numeric fields in the documents, or be generated by a provided script.
The stats that are returned by stats aggregation consist of: min, max, sum, count and avg.
The extended_stats aggregations is an extended version of the stats aggregation, where additional metrics are added such as sum_of_squares, variance, std_deviation and std_deviation_bounds.
Prerequisites:
Set up accounts index from accounts.json as explained in the link.
Solution Steps:
Case 1 - Stats Aggregation
GET accounts/_search
{
"aggregations" : {
"balance_stats" : {
"stats" : {
"field":"balance"
}
}
},
"size": 0
}
Response will contain:
...
"aggregations": {
"balance_stats": {
"count": 1000,
"min": 1011,
"max": 49989,
"avg": 25714.837,
"sum": 25714837
}
}
Case 2 - Extended Stats
GET accounts/_search
{
"aggregations" : {
"balance_stats" : {
"extended_stats" : {
"field":"balance"
}
}
},
"size": 0
}
Response will contain:
...
"aggregations": {
"balance_stats": {
"count": 1000,
"min": 1011,
"max": 49989,
"avg": 25714.837,
"sum": 25714837,
"sum_of_squares": 858626807735,
"variance": 197373965.79843104,
"std_deviation": 14048.984511288745,
"std_deviation_bounds": {
"upper": 53812.80602257749,
"lower": -2383.1320225774907
}
}
}
Recent comments