Stats aggregation

Stats aggregation computes the sum, average, min, max, and count of documents in a single pass:

GET bigginsight/_search
{
"aggregations": {
"download_stats": {
"stats": {
"field": "downloadTotal"
}
}
},
"size": 0
}

The structure of the stats request is the same as the other metric aggregations we have looked at so far, so nothing special is going on here.

The response should look like the following:

{
"took": 4,
...,
"hits": {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score": 0,
"hits": []
},
"aggregations": {
"download_stats": {
"count": 242835,
"min": 0,
"max": 241213,
"avg": 9049.102065188297,
"sum": 2197438700
}
}
}

As you can see, the response with the download_stats element contains count, min, max, average, and sum; everything is included in the same response. This is very handy, as it reduces the overhead of multiple requests, and also simplifies the client code.

Let's look at the extended stats aggregation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.43.206