Filter empty buckets from aggregation results
{ "size": 0, "aggs": { "colors": { "terms": { "field": "color" "min_doc_count": 1 }, "aggs": { "timestamps": { "terms": { "field": "timestamp", "min_doc_count": 1 }, "aggs": { "sum_manufacturing": { "sum": { "field": "hours" } }, "manufacturing_bucket_filter": { "bucket_selector": { "buckets_path": { "hours": "sum_manufacturing" }, "script": { "inline": "hours > 1000", "lang": "expression" } } }, "min_bucket_selector":{ "bucket_selector": { "buckets_path": {"count": "sum_manufacturing._bucket_count"}, "script": {"inline": "params.count != 0"} } } } } } } }}
I think this might solve your issue.