Combining Missing Aggregation with Other Aggregations
Missing aggregation can be combined with other aggregations to perform more complex analyses. For instance, you can use a terms aggregation to group products by category and then use a missing aggregation to count the number of products missing the price field in each category.
Query
GET /products/_search
{
"size": 0,
"aggs": {
"categories": {
"terms": {
"field": "category.keyword"
},
"aggs": {
"missing_price": {
"missing": {
"field": "price"
}
}
}
}
}
}
Output
{
"took": 15,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"categories": {
"buckets": [
{
"key": "electronics",
"doc_count": 1,
"missing_price": {
"doc_count": 0
}
},
{
"key": "clothing",
"doc_count": 1,
"missing_price": {
"doc_count": 1
}
},
{
"key": "books",
"doc_count": 1,
"missing_price": {
"doc_count": 0
}
}
]
}
}
}
In this example, the products are grouped by category, and within each category, the number of products missing the price field is counted.
Missing Aggregation in Elasticsearch
Elasticsearch is a powerful tool for full-text search and data analytics, and one of its core features is the aggregation framework. Aggregations allow you to summarize and analyze your data flexibly and efficiently.
Among the various types of aggregations available, the “missing” aggregation is particularly useful for dealing with incomplete data. This guide will explain what missing aggregation is, how it works, and provide detailed examples to help you understand its usage.