public static InternalAggregations reduce(List<InternalAggregations> aggregationsList,ReduceContext context){
  if (aggregationsList.isEmpty()) {
    return null;
  }
  Map<String,List<InternalAggregation>> aggByName=new HashMap<>();
  for (  InternalAggregations aggregations : aggregationsList) {
    for (    InternalAggregation aggregation : aggregations.aggregations) {
      List<InternalAggregation> aggs=aggByName.get(aggregation.getName());
      if (aggs == null) {
        aggs=new ArrayList<>(aggregationsList.size());
        aggByName.put(aggregation.getName(),aggs);
      }
      aggs.add(aggregation);
    }
  }
  List<InternalAggregation> reducedAggregations=new ArrayList<>();
  for (  Map.Entry<String,List<InternalAggregation>> entry : aggByName.entrySet()) {
    List<InternalAggregation> aggregations=entry.getValue();
    InternalAggregation first=aggregations.get(0);
    reducedAggregations.add(first.reduce(aggregations,context));
  }
  return new InternalAggregations(reducedAggregations);
}

public static InternalAggregations reduce ( List < InternalAggregations > aggregationsList , ReduceContext context ) { if ( aggregationsList . isEmpty ( ) ) { return null ; } Map < String , List < InternalAggregation > > aggByName = new HashMap < > ( ) ; for ( InternalAggregations aggregations : aggregationsList ) { for ( InternalAggregation aggregation : aggregations . aggregations ) { List < InternalAggregation > aggs = aggByName . get ( aggregation . getName ( ) ) ; if ( aggs == null ) { aggs = new ArrayList < > ( aggregationsList . size ( ) ) ; aggByName . put ( aggregation . getName ( ) , aggs ) ; } aggs . add ( aggregation ) ; } } List < InternalAggregation > reducedAggregations = new ArrayList < > ( ) ; for ( Map . Entry < String , List < InternalAggregation > > entry : aggByName . entrySet ( ) ) { List < InternalAggregation > aggregations = entry . getValue ( ) ; InternalAggregation first = aggregations . get ( 0 ) ; reducedAggregations . add ( first . reduce ( aggregations , context ) ) ; } return new InternalAggregations ( reducedAggregations ) ; }
reduces the given lists of addaggregation .
