use of io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse in project gravitee-management-rest-api by gravitee-io.
the class AnalyticsServiceImpl method execute.
@Override
public HistogramAnalytics execute(DateHistogramQuery query) {
try {
DateHistogramQueryBuilder queryBuilder = QueryBuilders.dateHistogram().query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root(query.getRootField(), query.getRootIdentifier());
if (query.getAggregations() != null) {
query.getAggregations().stream().forEach(aggregation -> queryBuilder.aggregation(AggregationType.valueOf(aggregation.type().name()), aggregation.field()));
}
DateHistogramResponse response = analyticsRepository.query(queryBuilder.build());
return convert(response);
} catch (AnalyticsException ae) {
logger.error("Unable to calculate analytics: ", ae);
throw new TechnicalManagementException("Unable to calculate analytics", ae);
}
}
Aggregations