private SearchRequestBuilder standardSearchRequest( String query, Set<String> indices, int limit, int offset, TimeRange range, Sorting sort) throws IndexHelper.InvalidRangeFormatException { if (query == null || query.trim().isEmpty()) { query = "*"; } SearchRequestBuilder srb = c.prepareSearch(); srb.setIndices(indices.toArray(new String[] {})); if (query.trim().equals("*")) { srb.setQuery(matchAllQuery()); } else { QueryStringQueryBuilder qs = queryString(query); qs.allowLeadingWildcard(server.getConfiguration().isAllowLeadingWildcardSearches()); srb.setQuery(qs); } srb.setFrom(offset); if (limit > 0) { srb.setSize(limit); } if (range != null) { srb.setFilter(IndexHelper.getTimestampRangeFilter(range)); } if (sort != null) { srb.addSort(sort.getField(), sort.asElastic()); } return srb; }
private BoolFilterBuilder standardFilters(TimeRange range, String filter) throws IndexHelper.InvalidRangeFormatException { BoolFilterBuilder bfb = FilterBuilders.boolFilter(); boolean set = false; if (range != null) { bfb.must(IndexHelper.getTimestampRangeFilter(range)); set = true; } if (filter != null && !filter.isEmpty() && !filter.equals("*")) { bfb.must(FilterBuilders.queryFilter(QueryBuilders.queryString(filter))); set = true; } if (!set) { throw new RuntimeException("Either range or filter must be set."); } return bfb; }