示例#1
0
  public FieldStatsResult fieldStats(String field, String query, String filter, TimeRange range)
      throws FieldTypeException, IndexHelper.InvalidRangeFormatException {
    SearchRequestBuilder srb;

    if (filter == null) {
      srb = standardSearchRequest(query, IndexHelper.determineAffectedIndices(server, range));
    } else {
      srb =
          filteredSearchRequest(query, filter, IndexHelper.determineAffectedIndices(server, range));
    }

    StatisticalFacetBuilder stats = new StatisticalFacetBuilder(STATS_FACET_NAME);
    stats.global(false);

    stats.facetFilter(standardFilters(range, filter));

    stats.field(field);

    srb.addFacet(stats);

    SearchResponse r;
    final SearchRequest request;
    try {
      request = srb.request();
      r = c.search(request).actionGet();
    } catch (org.elasticsearch.action.search.SearchPhaseExecutionException e) {
      throw new FieldTypeException(e);
    }

    return new FieldStatsResult(
        (StatisticalFacet) r.getFacets().facet(STATS_FACET_NAME),
        query,
        request.source(),
        r.getTook());
  }
示例#2
0
  public TermsResult terms(String field, int size, String query, String filter, TimeRange range)
      throws IndexHelper.InvalidRangeFormatException {
    if (size == 0) {
      size = 50;
    }

    SearchRequestBuilder srb;
    if (filter == null) {
      srb = standardSearchRequest(query, IndexHelper.determineAffectedIndices(server, range));
    } else {
      srb =
          filteredSearchRequest(query, filter, IndexHelper.determineAffectedIndices(server, range));
    }

    TermsFacetBuilder terms = new TermsFacetBuilder(TERMS_FACET_NAME);
    terms.global(false);
    terms.field(field);
    terms.size(size);

    terms.facetFilter(standardFilters(range, filter));

    srb.addFacet(terms);

    final SearchRequest request = srb.request();
    SearchResponse r = c.search(request).actionGet();

    return new TermsResult(
        (TermsFacet) r.getFacets().facet(TERMS_FACET_NAME), query, request.source(), r.getTook());
  }
示例#3
0
  public HistogramResult histogram(
      String query, Indexer.DateHistogramInterval interval, String filter, TimeRange range)
      throws IndexHelper.InvalidRangeFormatException {
    DateHistogramFacetBuilder fb =
        FacetBuilders.dateHistogramFacet("histogram")
            .field("timestamp")
            .interval(interval.toString().toLowerCase());

    fb.facetFilter(standardFilters(range, filter));

    QueryStringQueryBuilder qs = queryString(query);
    qs.allowLeadingWildcard(server.getConfiguration().isAllowLeadingWildcardSearches());

    SearchRequestBuilder srb = c.prepareSearch();
    srb.setIndices(IndexHelper.determineAffectedIndices(server, range).toArray(new String[] {}));
    srb.setQuery(qs);
    srb.addFacet(fb);

    final SearchRequest request = srb.request();
    SearchResponse r = c.search(request).actionGet();
    return new DateHistogramResult(
        (DateHistogramFacet) r.getFacets().facet("histogram"),
        query,
        request.source(),
        interval,
        r.getTook());
  }
示例#4
0
  public CountResult count(String query, TimeRange range, String filter)
      throws IndexHelper.InvalidRangeFormatException {
    Set<String> indices = IndexHelper.determineAffectedIndices(server, range);

    SearchRequest request;
    if (filter == null) {
      request = standardSearchRequest(query, indices, range).request();
    } else {
      request = filteredSearchRequest(query, filter, indices, range).request();
    }
    request.searchType(SearchType.COUNT);

    SearchResponse r = c.search(request).actionGet();
    return new CountResult(r.getHits().getTotalHits(), r.getTookInMillis());
  }
示例#5
0
  public SearchResult search(
      String query, String filter, TimeRange range, int limit, int offset, Sorting sorting)
      throws IndexHelper.InvalidRangeFormatException {
    if (limit <= 0) {
      limit = LIMIT;
    }

    Set<String> indices = IndexHelper.determineAffectedIndices(server, range);

    SearchRequest request;

    if (filter == null) {
      request = standardSearchRequest(query, indices, limit, offset, range, sorting).request();
    } else {
      request =
          filteredSearchRequest(query, filter, indices, limit, offset, range, sorting).request();
    }

    SearchResponse r = c.search(request).actionGet();
    return new SearchResult(r.getHits(), indices, query, request.source(), r.getTook());
  }