use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.
the class ShardSizeTermsIT method testWithShardSizeDoubleSingleShard.
public void testWithShardSizeDoubleSingleShard() throws Exception {
createIdx("type=double");
indexData();
SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1).setQuery(matchAllQuery()).addAggregation(terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))).execute().actionGet();
Terms terms = response.getAggregations().get("keys");
Collection<Terms.Bucket> buckets = terms.getBuckets();
assertThat(buckets.size(), equalTo(3));
Map<Integer, Long> expected = new HashMap<>();
expected.put(1, 5L);
expected.put(2, 4L);
expected.put(3, 3L);
for (Terms.Bucket bucket : buckets) {
assertThat(bucket.getDocCount(), equalTo(expected.get(bucket.getKeyAsNumber().intValue())));
}
}
use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.
the class LongTermsIT method testSingleValueFieldOrderedByTermDesc.
public void testSingleValueFieldOrderedByTermDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.term(false))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
assertThat(terms.getBuckets().size(), equalTo(5));
int i = 4;
for (Terms.Bucket bucket : terms.getBuckets()) {
assertThat(bucket, notNullValue());
assertThat(key(bucket), equalTo("" + i));
assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i));
assertThat(bucket.getDocCount(), equalTo(1L));
i--;
}
}
use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.
the class LongTermsIT method testSingleValuedFieldOrderedByMultiValueSubAggregationAsc.
public void testSingleValuedFieldOrderedByMultiValueSubAggregationAsc() throws Exception {
boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.aggregation("stats.avg", asc)).subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
assertThat(terms.getBuckets().size(), equalTo(5));
for (int i = 0; i < 5; i++) {
Terms.Bucket bucket = terms.getBucketByKey("" + i);
assertThat(bucket, notNullValue());
assertThat(key(bucket), equalTo("" + i));
assertThat(bucket.getDocCount(), equalTo(1L));
Stats stats = bucket.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getMax(), equalTo((double) i));
}
}
use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.
the class LongTermsIT method testSingleValueFieldWithMaxSize.
public void testSingleValueFieldWithMaxSize() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).size(20).collectMode(randomFrom(SubAggCollectionMode.values())).order(// we need to sort by terms cause we're checking the first 20 values
Terms.Order.term(true))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
assertThat(terms.getBuckets().size(), equalTo(20));
for (int i = 0; i < 20; i++) {
Terms.Bucket bucket = terms.getBucketByKey("" + i);
assertThat(bucket, notNullValue());
assertThat(key(bucket), equalTo("" + i));
assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i));
assertThat(bucket.getDocCount(), equalTo(1L));
}
}
use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.
the class LongTermsIT method testUnmapped.
public void testUnmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).size(randomIntBetween(1, 5)).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
assertThat(terms.getBuckets().size(), equalTo(0));
}
Aggregations