class ElasticsearchFacetResultHelper {

    public static FacetResult transformFromEsAggregation(Aggregation aggregation) {
        FacetResult facetResult = new FacetResult();
        facetResult.setName(aggregation.getName());
        String aggType = aggregation.getType();
        switch (aggType) {
            case DateRangeAggregationBuilder.NAME:
                facetResult.setBuckets(extractBucketRangeAggregation(aggregation));
                break;
            case StringTerms.NAME:
                facetResult.setBuckets(extractBucketTermsAggregation(aggregation));
                break;
            case FiltersAggregationBuilder.NAME:
                facetResult.setBuckets(extractBucketFiltersAggregation(aggregation));
                break;
            case NestedAggregationBuilder.NAME:
                facetResult.setBuckets(extractBucketNestedAggregation(aggregation));
                break;
            default:
                break;
        }
        return facetResult;
    }

}