I don't believe there's a way to get the total bucket count, because the composite
agg doesn't know how many buckets there are until it has paged through them all.
I think the best you can do is keep a running counter client-side and increment it with each page that you receive.
That's the trade-off that composite
pays; memory-friendly, streaming collection of results at the expense of multiple round-trips and not knowing the buckets up-front.