Filter Aggregation
The filter aggregation groups documents that match a specific filter. Let’s group products that have a rating of 4 or higher.
Query
GET /products/_search
{
"size": 0,
"aggs": {
"high_rated_products": {
"filter": {
"range": {
"rating": {
"gte": 4
}
}
}
}
}
}
Output
{
"aggregations": {
"high_rated_products": {
"doc_count": 7
}
}
}
In this example, we group products with a rating of 4 or higher, and the number of such products is counted.
Bucket Aggregation in Elasticsearch
Elasticsearch is a robust tool not only for full-text search but also for data analytics. One of the core features that make Elasticsearch powerful is its aggregation framework, particularly bucket aggregations. Bucket aggregations allow you to group documents into buckets based on certain criteria, making it easier to analyze and summarize your data.
This article will explain what bucket aggregations are, how they work, and provide detailed examples to help you understand their usage.