code: private List parseAggregatedResponse(SearchResponse response, KunderaQuery query, MetamodelImpl metaModel,
              Class clazz, EntityMetadata entityMetadata)
      {
          List results, temp = new ArrayList<>();
          InternalAggregations internalAggs = ((InternalFilter) response.getAggregations().getAsMap()
                  .get(ESConstants.AGGREGATION_NAME)).getAggregations();
  
          if (query.isSelectStatement() && KunderaQueryUtils.hasGroupBy(query.getJpqlExpression()))
          {
              Terms buckets = (Terms) (internalAggs).getAsMap().get(ESConstants.GROUP_BY);
  
              filterBuckets(buckets, query);
  
              results = onIterateBuckets(buckets, query, metaModel, clazz, entityMetadata);
          }
          else
          {
              results = new ArrayList<>();
              temp = buildRecords(internalAggs, response.getHits(), query, metaModel, clazz, entityMetadata);
  
              for (Object value : temp)
              {
                  if (!value.toString().equalsIgnoreCase(ESConstants.INFINITY))
                  {
                      results.add(value);
                  }
              }
          }
          return results;
      }
docs: Parses the aggregated response.
  
  @param response
  the response
  @param query
  the query
  @param metaModel
  the meta model
  @param clazz
  the clazz
  @param entityMetadata
  the entity metadata
  @return the list