Good spot. It looks like the code is designed to cater for both "normal" use and what many might consider to be an edge-case - where min_doc_count is set to zero. In the zero-match scenario the user wants ALL buckets, not just those that matched the query, hence we iterate over all terms.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.