Search in sources :

Example 6 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class TDigestPercentilesIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    final double[] pcts = randomPercentiles();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(randomCompression(percentiles("percentiles")).field("value").percentiles(pcts))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10L));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    Percentiles percentiles = global.getAggregations().get("percentiles");
    assertThat(percentiles, notNullValue());
    assertThat(percentiles.getName(), equalTo("percentiles"));
    assertThat(global.getProperty("percentiles"), sameInstance(percentiles));
}
Also used : Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 7 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class TDigestPercentileRanksIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    final double[] pcts = randomPercents(minValue, maxValue);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(randomCompression(percentileRanks("percentile_ranks")).field("value").values(pcts))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10L));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    PercentileRanks values = global.getAggregations().get("percentile_ranks");
    assertThat(values, notNullValue());
    assertThat(values.getName(), equalTo("percentile_ranks"));
    assertThat(global.getProperty("percentile_ranks"), sameInstance(values));
}
Also used : PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 8 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project sonarqube by SonarSource.

the class IssueIndex method listTags.

public List<String> listTags(IssueQuery query, @Nullable String textQuery, int maxNumberOfTags) {
    SearchRequestBuilder requestBuilder = getClient().prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE, RuleIndexDefinition.INDEX_TYPE_RULE);
    requestBuilder.setQuery(boolQuery().must(matchAllQuery()).filter(createBoolFilter(query)));
    GlobalBuilder topAggreg = AggregationBuilders.global("tags");
    String tagsOnIssuesSubAggregation = "tags__issues";
    String tagsOnRulesSubAggregation = "tags__rules";
    TermsBuilder issueTags = AggregationBuilders.terms(tagsOnIssuesSubAggregation).field(IssueIndexDefinition.FIELD_ISSUE_TAGS).size(maxNumberOfTags).order(Terms.Order.term(true)).minDocCount(1L);
    TermsBuilder ruleTags = AggregationBuilders.terms(tagsOnRulesSubAggregation).field(RuleIndexDefinition.FIELD_RULE_ALL_TAGS).size(maxNumberOfTags).order(Terms.Order.term(true)).minDocCount(1L);
    if (textQuery != null) {
        String escapedTextQuery = escapeSpecialRegexChars(textQuery);
        issueTags.include(format(SUBSTRING_MATCH_REGEXP, escapedTextQuery));
        ruleTags.include(format(SUBSTRING_MATCH_REGEXP, escapedTextQuery));
    }
    SearchResponse searchResponse = requestBuilder.addAggregation(topAggreg.subAggregation(issueTags).subAggregation(ruleTags)).get();
    Global allTags = searchResponse.getAggregations().get("tags");
    SortedSet<String> result = Sets.newTreeSet();
    Terms issuesResult = allTags.getAggregations().get(tagsOnIssuesSubAggregation);
    Terms rulesResult = allTags.getAggregations().get(tagsOnRulesSubAggregation);
    result.addAll(EsUtils.termsKeys(issuesResult));
    result.addAll(EsUtils.termsKeys(rulesResult));
    List<String> resultAsList = Lists.newArrayList(result);
    return resultAsList.size() > maxNumberOfTags && maxNumberOfTags > 0 ? resultAsList.subList(0, maxNumberOfTags) : resultAsList;
}
Also used : GlobalBuilder(org.elasticsearch.search.aggregations.bucket.global.GlobalBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) TermsBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 9 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class TopHitsIT method testBasicsGetProperty.

public void testBasicsGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(topHits("hits"))).execute().actionGet();
    assertSearchResponse(searchResponse);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    TopHits topHits = global.getAggregations().get("hits");
    assertThat(topHits, notNullValue());
    assertThat(topHits.getName(), equalTo("hits"));
    assertThat((TopHits) global.getProperty("hits"), sameInstance(topHits));
}
Also used : TopHits(org.elasticsearch.search.aggregations.metrics.tophits.TopHits) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 10 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class StatsIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(stats("stats").field("value"))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10L));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    Stats stats = global.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    Stats statsFromProperty = (Stats) global.getProperty("stats");
    assertThat(statsFromProperty, notNullValue());
    assertThat(statsFromProperty, sameInstance(stats));
    double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10;
    assertThat(stats.getAvg(), equalTo(expectedAvgValue));
    assertThat((double) global.getProperty("stats.avg"), equalTo(expectedAvgValue));
    double expectedMinValue = 1.0;
    assertThat(stats.getMin(), equalTo(expectedMinValue));
    assertThat((double) global.getProperty("stats.min"), equalTo(expectedMinValue));
    double expectedMaxValue = 10.0;
    assertThat(stats.getMax(), equalTo(expectedMaxValue));
    assertThat((double) global.getProperty("stats.max"), equalTo(expectedMaxValue));
    double expectedSumValue = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
    assertThat(stats.getSum(), equalTo(expectedSumValue));
    assertThat((double) global.getProperty("stats.sum"), equalTo(expectedSumValue));
    long expectedCountValue = 10;
    assertThat(stats.getCount(), equalTo(expectedCountValue));
    assertThat((double) global.getProperty("stats.count"), equalTo((double) expectedCountValue));
}
Also used : Stats(org.elasticsearch.search.aggregations.metrics.stats.Stats) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)23 Global (org.elasticsearch.search.aggregations.bucket.global.Global)23 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)20 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)3 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)3 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2 AggregationBuilders.dateHistogram (org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram)2 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)2 PercentileRanks (org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks)2 Percentiles (org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles)2 Stats (org.elasticsearch.search.aggregations.metrics.stats.Stats)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 Script (org.elasticsearch.script.Script)1 GlobalBuilder (org.elasticsearch.search.aggregations.bucket.global.GlobalBuilder)1 Missing (org.elasticsearch.search.aggregations.bucket.missing.Missing)1 TermsBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder)1