code: private List onIterateBuckets(Terms buckets, KunderaQuery query, MetamodelImpl metaModel, Class clazz,
              EntityMetadata entityMetadata)
      {
          List temp, results = new ArrayList<>();
  
          for (Terms.Bucket entry : buckets.getBuckets())
          {
              logger.debug("key [{}], doc_count [{}]", entry.getKey(), entry.getDocCount());
              Aggregations aggregations = entry.getAggregations();
              TopHits topHits = aggregations.get(ESConstants.TOP_HITS);
  
              temp = buildRecords((InternalAggregations) aggregations, topHits.getHits(), query, metaModel, clazz,
                      entityMetadata);
              results.add(temp.size() == 1 ? temp.get(0) : temp);
          }
  
          return results;
      }
docs: On iterate buckets.
  
  @param buckets
  the buckets
  @param query
  the query
  @param metaModel
  the meta model
  @param clazz
  the clazz
  @param entityMetadata
  the entity metadata
  @return the list