Filters Aggregation
The filter aggregation groups documents based on multiple filters. Let’s group products based on multiple rating ranges.
Query
GET /products/_search
{
"size": 0,
"aggs": {
"rating_filters": {
"filters": {
"filters": {
"high_rating": {
"range": {
"rating": {
"gte": 4
}
}
},
"low_rating": {
"range": {
"rating": {
"lt": 4
}
}
}
}
}
}
}
}
Output
{
"aggregations": {
"rating_filters": {
"buckets": {
"high_rating": {
"doc_count": 7
},
"low_rating": {
"doc_count": 3
}
}
}
}
}
In this example, products are grouped based on two rating ranges, and the number of products in each range 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.
Contact Us