private static void removeEmptyAggregation(JsonNode node) {
    if (!node.has(AGGREGATIONS)) {
      node.elements().forEachRemaining(AggregateQueryBuilder::removeEmptyAggregation);
      return;
    }
    JsonNode agg = node.get(AGGREGATIONS);
    if (agg.size() == 0) {
      ((ObjectNode) node).remove(AGGREGATIONS);
    } else {
      removeEmptyAggregation(agg);
    }
  }
Used for constructing (possibly nested) Elastic aggregation nodes.
criteria/elasticsearch/src/org/immutables/criteria/elasticsearch/AggregateQueryBuilder.java