final Root<SearchRequest> requestRoot = cbQuery.from(SearchRequest.class);
final Path<ISODate> requestDate = requestRoot.get(SearchRequest_.requestDate);
final Expression<String> requestDateByType = cb.substring(requestDate.get(ISODate_.dateAndTime), 1, dateInterval.getSubstringEnd());
Predicate whereClause = cb.and(cb.lessThanOrEqualTo(requestDate, to), cb.greaterThanOrEqualTo(requestDate, from));
if (spec != null) {
whereClause = cb.and(whereClause, spec.toPredicate(requestRoot, cbQuery, cb));
}
final CompoundSelection<Tuple> selection = cb.tuple(requestDateByType, cb.count(requestRoot));
cbQuery.select(selection)