No of buckets creation for composite aggregation

lets say, I have 40000 unique buckets, can i use composite aggregation to fetch 1000 buckets at once, repeat the call until i fetch all the buckets

Sure, I cannot see why not, it is design exactly for that.