code: private void populateGroupByResponse(Map<String, Object> aggregations, Iterable<Expression> resultOrderIterable,
              List<Object> results, Client client, EntityMetadata m)
      {
          List temp;
          Object entity = null;
          for (String entry : aggregations.keySet())
          {
              entity = null;
              Object obj = aggregations.get(entry);
              temp = new ArrayList<>();
              Iterator<Expression> resultOrder = resultOrderIterable.iterator();
              while (resultOrder.hasNext())
              {
                  Expression expression = (Expression) resultOrder.next();
  
                  if (AggregateFunction.class.isAssignableFrom(expression.getClass()))
                  {
                      if (((Map) obj).get(expression.toParsedText()) != null)
                      {
                          temp.add(((Map) obj).get(expression.toParsedText()));
                      }
                  }
                  else
                  {
                      if (entity == null)
                      {
                          entity = findUsingLucene(m, client, new Object[] { entry }).get(0);
                      }
                      temp.add(getEntityFieldValue(m, entity, expression.toParsedText()));
                  }
              }
              results.add(temp.size() == 1 ? temp.get(0) : temp);
          }
      }
docs: Populate group by response.
  
  @param aggregations
  the aggregations
  @param resultOrderIterable
  the result order iterable
  @param results
  the results
  @param client
  the client
  @param m
  the m