code: public Map<String, Object> parseAggregations(SearchResponse response, KunderaQuery query, MetamodelImpl metaModel,
              Class clazz, EntityMetadata m)
      {
          Map<String, Object> aggregationsMap = new LinkedHashMap<>();
          if (query.isAggregated() == true && response.getAggregations() != null)
          {
              InternalAggregations internalAggs = ((InternalFilter) response.getAggregations().getAsMap()
                      .get(ESConstants.AGGREGATION_NAME)).getAggregations();
  
              ListIterable<Expression> iterable = getSelectExpressionOrder(query);
  
              if (query.isSelectStatement() && KunderaQueryUtils.hasGroupBy(query.getJpqlExpression()))
              {
                  Terms buckets = (Terms) (internalAggs).getAsMap().get(ESConstants.GROUP_BY);
  
                  filterBuckets(buckets, query);
  
                  for (Terms.Bucket bucket : buckets.getBuckets())
                  {
                      logger.debug("key [{}], doc_count [{}]", bucket.getKey(), bucket.getDocCount());
  
                      TopHits topHits = bucket.getAggregations().get(ESConstants.TOP_HITS);
                      aggregationsMap.put(topHits.getHits().getAt(0).getId(),
                              buildRecords(iterable, (InternalAggregations) bucket.getAggregations()));
                  }
              }
              else
              {
                  aggregationsMap = buildRecords(iterable, internalAggs);
              }
          }
          return aggregationsMap;
      }
docs: Parses the aggregations.
  
  @param response
  the response
  @param query
  the query
  @param metaModel
  the meta model
  @param clazz
  the clazz
  @param EntityMetadata
  the m
  @return the map