private Query buildESQuery(String startDate, String endDate) { // build query Query query = new Query(); Filtered filtered = null; FilteredWithQuery filteredWithQuery = null; CreatedDate createdDate = new CreatedDate(); createdDate.setGte(startDate); createdDate.setLte(endDate); Range range = new Range(); range.setCreatedDate(createdDate); And and = new And(); and.setRange(range); List<And> andList = new ArrayList<And>(); andList.add(and); FilterWithAnd fwa = new FilterWithAnd(); fwa.setAnd(andList); if (groupsNames != null) { QueryWithTerms qwt = new QueryWithTerms(); Terms terms = new Terms(); terms.setGroupName(PerisaiUtil.userGroupListToArr(groupsNames)); qwt.setTerms(terms); filteredWithQuery = new FilteredWithQuery(); filteredWithQuery.setQuery(qwt); filteredWithQuery.setFilter(fwa); query.setFiltered(filteredWithQuery); } else { filtered = new Filtered(); filtered.setFilter(fwa); query.setFiltered(filtered); } return query; }