code: private AggregationBuilder addHavingClause(Expression havingExpression, AggregationBuilder aggregationBuilder,
              EntityMetadata entityMetadata)
      {
          if (havingExpression instanceof ComparisonExpression)
          {
              Expression expression = ((ComparisonExpression) havingExpression).getLeftExpression();
              if (!isAggregationExpression(expression))
              {
                  logger.error("Having clause conditions over non metric aggregated are not supported.");
                  throw new UnsupportedOperationException(
                          "Currently, Having clause without Metric aggregations are not supported.");
              }
  
              return checkIfKeyExists(expression.toParsedText()) ? aggregationBuilder
                      .subAggregation(getMetricsAggregation(expression, entityMetadata)) : aggregationBuilder;
          }
          else if (havingExpression instanceof AndExpression)
          {
              AndExpression andExpression = (AndExpression) havingExpression;
              addHavingClause(andExpression.getLeftExpression(), aggregationBuilder, entityMetadata);
              addHavingClause(andExpression.getRightExpression(), aggregationBuilder, entityMetadata);
  
              return aggregationBuilder;
          }
          else if (havingExpression instanceof OrExpression)
          {
              OrExpression orExpression = (OrExpression) havingExpression;
              addHavingClause(orExpression.getLeftExpression(), aggregationBuilder, entityMetadata);
              addHavingClause(orExpression.getRightExpression(), aggregationBuilder, entityMetadata);
  
              return aggregationBuilder;
          }
          else
          {
              logger.error(havingExpression + "not supported in having clause.");
              throw new UnsupportedOperationException(havingExpression + "not supported in having clause.");
          }
      }
docs: Adds the having clauses.
  
  @param havingExpression
  the having expression
  @param aggregationBuilder
  the aggregation builder
  @param entityMetadata
  the entity metadata
  @return the aggregation builder