Search in sources :

Example 1 with TermsResult

use of org.graylog2.indexer.results.TermsResult in project graylog2-server by Graylog2.

the class SearchesTest method testTerms.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTerms() throws Exception {
    TermsResult result = searches.terms("n", 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(result.getTotal()).isEqualTo(10L);
    assertThat(result.getMissing()).isEqualTo(2L);
    assertThat(result.getTerms()).hasSize(4).containsEntry("1", 2L).containsEntry("2", 2L).containsEntry("3", 3L).containsEntry("4", 1L);
}
Also used : TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 2 with TermsResult

use of org.graylog2.indexer.results.TermsResult in project graylog2-server by Graylog2.

the class SearchesTest method testTermsWithNonExistingIndex.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTermsWithNonExistingIndex() throws Exception {
    final SortedSet<IndexRange> indexRanges = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(MongoIndexRange.create(INDEX_NAME, new DateTime(0L, UTC), new DateTime(2015, 1, 1, 0, 0, UTC), DateTime.now(UTC), 0, null)).add(MongoIndexRange.create("does-not-exist", new DateTime(0L, UTC), new DateTime(2015, 1, 1, 0, 0, UTC), DateTime.now(UTC), 0, null)).build();
    when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indexRanges);
    TermsResult result = searches.terms("n", 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(result.getTotal()).isEqualTo(10L);
    assertThat(result.getMissing()).isEqualTo(2L);
    assertThat(result.getTerms()).hasSize(4).containsEntry("1", 2L).containsEntry("2", 2L).containsEntry("3", 3L).containsEntry("4", 1L);
}
Also used : MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) IndexRange(org.graylog2.indexer.ranges.IndexRange) TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 3 with TermsResult

use of org.graylog2.indexer.results.TermsResult in project graylog2-server by Graylog2.

the class QuickvaluesWidgetStrategy method compute.

@Override
public ComputationResult compute() {
    String filter = null;
    if (!isNullOrEmpty(streamId)) {
        filter = "streams:" + streamId;
    }
    final TermsResult terms = searches.terms(field, 50, query, filter, this.timeRange);
    Map<String, Object> result = Maps.newHashMap();
    result.put("terms", terms.getTerms());
    result.put("total", terms.getTotal());
    result.put("other", terms.getOther());
    result.put("missing", terms.getMissing());
    return new ComputationResult(result, terms.took().millis());
}
Also used : ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult) TermsResult(org.graylog2.indexer.results.TermsResult)

Example 4 with TermsResult

use of org.graylog2.indexer.results.TermsResult in project graylog2-server by Graylog2.

the class Searches method terms.

public TermsResult terms(String field, int size, String query, String filter, TimeRange range, Sorting.Direction sorting) {
    Terms.Order termsOrder;
    if (size == 0) {
        size = 50;
    }
    if (sorting == Sorting.Direction.DESC) {
        termsOrder = Terms.Order.count(false);
    } else {
        termsOrder = Terms.Order.count(true);
    }
    SearchRequestBuilder srb;
    if (filter == null) {
        srb = standardSearchRequest(query, determineAffectedIndices(range, null), range);
    } else {
        srb = filteredSearchRequest(query, filter, determineAffectedIndices(range, filter), range);
    }
    FilterAggregationBuilder builder = AggregationBuilders.filter(AGG_FILTER).subAggregation(AggregationBuilders.terms(AGG_TERMS).field(field).size(size).order(termsOrder)).subAggregation(AggregationBuilders.missing("missing").field(field)).filter(standardAggregationFilters(range, filter));
    srb.addAggregation(builder);
    final SearchRequest request = srb.request();
    SearchResponse r = c.search(request).actionGet();
    recordEsMetrics(r, range);
    final Filter f = r.getAggregations().get(AGG_FILTER);
    return new TermsResult(f.getAggregations().get(AGG_TERMS), f.getAggregations().get("missing"), f.getDocCount(), query, request.source(), r.getTook());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) TermsResult(org.graylog2.indexer.results.TermsResult) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 5 with TermsResult

use of org.graylog2.indexer.results.TermsResult in project graylog2-server by Graylog2.

the class SearchesTest method testTermsAscending.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTermsAscending() throws Exception {
    TermsResult result = searches.terms("n", 1, "*", null, AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), Sorting.Direction.ASC);
    assertThat(result.getTotal()).isEqualTo(10L);
    assertThat(result.getMissing()).isEqualTo(2L);
    assertThat(result.getTerms()).hasSize(1).containsEntry("4", 1L);
}
Also used : TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

TermsResult (org.graylog2.indexer.results.TermsResult)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)4 ZonedDateTime (java.time.ZonedDateTime)4 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)4 Histogram (com.codahale.metrics.Histogram)1 Timer (com.codahale.metrics.Timer)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)1 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)1 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)1 IndexRange (org.graylog2.indexer.ranges.IndexRange)1 MongoIndexRange (org.graylog2.indexer.ranges.MongoIndexRange)1 ComputationResult (org.graylog2.plugin.dashboards.widgets.ComputationResult)1