Getting top_buckets(size=5) by using max(bucket.doc._score) + also getting the top_document() on each bucket

Hi,

I'm having trouble getting top_buckets by a field "program_id" and then getting the top document for each field and also ordering buckets by the document with the highest _score.

Any ideas ?

So it should return 20 buckets ordered by the bucket's.top_document._score and the 1 document for each bucket ordered by doc._score.

Thank You