Filter by count in elasticsearch
Hi you can use the top_hits query, it does not suit situation where you expect to find a lot of documents for a term. Try it in your own situation. But I think this query can find what you want.
GET /programming/languages/_search?search_type=count{ "aggs": { "byTop": { "terms": { "field": "type", "min_doc_count": 2, "size": 10 }, "aggs": { "theTop": { "top_hits": { "size":5 } } } } }}