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));
}
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));
}
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;
}
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));
}
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));
}
Aggregations