Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  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;
  }