code: private AggregationBuilder buildSelectAggregations(AggregationBuilder aggregationBuilder,
              SelectStatement selectStatement, EntityMetadata entityMetadata)
      {
          Expression expression = ((SelectClause) selectStatement.getSelectClause()).getSelectExpression();
  
          if (expression instanceof CollectionExpression)
          {
              aggregationBuilder = appendAggregation((CollectionExpression) expression, entityMetadata,
                      aggregationBuilder);
          }
          else
          {
              if (isAggregationExpression(expression) && checkIfKeyExists(expression.toParsedText()))
                  aggregationBuilder.subAggregation(getMetricsAggregation(expression, entityMetadata));
          }
          return aggregationBuilder;
      }
docs: Builds the select aggregations.
  
  @param selectStatement
  the select statement
  @param entityMetadata
  the entity metadata
  @param filter
  the filter
  @return the filter aggregation builder