use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class GeoHashGridIT method testUnmapped.
public void testUnmapped() throws Exception {
for (int precision = 1; precision <= PRECISION; precision++) {
SearchResponse response = client().prepareSearch("idx_unmapped").addAggregation(geohashGrid("geohashgrid").field("location").precision(precision)).execute().actionGet();
assertSearchResponse(response);
GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
assertThat(geoGrid.getBuckets().size(), equalTo(0));
}
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class GeoHashGridIT method testMultivalued.
public void testMultivalued() throws Exception {
for (int precision = 1; precision <= PRECISION; precision++) {
SearchResponse response = client().prepareSearch("multi_valued_idx").addAggregation(geohashGrid("geohashgrid").field("location").precision(precision)).execute().actionGet();
assertSearchResponse(response);
GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
for (GeoHashGrid.Bucket cell : geoGrid.getBuckets()) {
String geohash = cell.getKeyAsString();
long bucketCount = cell.getDocCount();
int expectedBucketCount = multiValuedExpectedDocCountsForGeoHash.get(geohash);
assertNotSame(bucketCount, 0);
assertEquals("Geohash " + geohash + " has wrong doc count ", expectedBucketCount, bucketCount);
}
}
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class GlobalIT method testWithStatsSubAggregator.
public void testWithStatsSubAggregator() throws Exception {
SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.termQuery("tag", "tag1")).addAggregation(global("global").subAggregation(stats("value_stats").field("value"))).execute().actionGet();
assertSearchResponse(response);
Global global = response.getAggregations().get("global");
assertThat(global, notNullValue());
assertThat(global.getName(), equalTo("global"));
assertThat(global.getDocCount(), equalTo((long) numDocs));
assertThat((long) global.getProperty("_count"), equalTo((long) numDocs));
assertThat(global.getAggregations().asList().isEmpty(), is(false));
Stats stats = global.getAggregations().get("value_stats");
assertThat((Stats) global.getProperty("value_stats"), sameInstance(stats));
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("value_stats"));
long sum = 0;
for (int i = 0; i < numDocs; ++i) {
sum += i + 1;
}
assertThat(stats.getAvg(), equalTo((double) sum / numDocs));
assertThat(stats.getMin(), equalTo(1.0));
assertThat(stats.getMax(), equalTo((double) numDocs));
assertThat(stats.getCount(), equalTo((long) numDocs));
assertThat(stats.getSum(), equalTo((double) sum));
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class BooleanTermsIT method testSingleValueField.
public void testSingleValueField() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
final int bucketCount = numSingleFalses > 0 && numSingleTrues > 0 ? 2 : numSingleFalses + numSingleTrues > 0 ? 1 : 0;
assertThat(terms.getBuckets().size(), equalTo(bucketCount));
Terms.Bucket bucket = terms.getBucketByKey("false");
if (numSingleFalses == 0) {
assertNull(bucket);
} else {
assertNotNull(bucket);
assertEquals(numSingleFalses, bucket.getDocCount());
assertEquals("false", bucket.getKeyAsString());
}
bucket = terms.getBucketByKey("true");
if (numSingleTrues == 0) {
assertNull(bucket);
} else {
assertNotNull(bucket);
assertEquals(numSingleTrues, bucket.getDocCount());
assertEquals("true", bucket.getKeyAsString());
}
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class BooleanTermsIT method testMultiValueField.
public void testMultiValueField() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(MULTI_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
final int bucketCount = numMultiFalses > 0 && numMultiTrues > 0 ? 2 : numMultiFalses + numMultiTrues > 0 ? 1 : 0;
assertThat(terms.getBuckets().size(), equalTo(bucketCount));
Terms.Bucket bucket = terms.getBucketByKey("false");
if (numMultiFalses == 0) {
assertNull(bucket);
} else {
assertNotNull(bucket);
assertEquals(numMultiFalses, bucket.getDocCount());
assertEquals("false", bucket.getKeyAsString());
}
bucket = terms.getBucketByKey("true");
if (numMultiTrues == 0) {
assertNull(bucket);
} else {
assertNotNull(bucket);
assertEquals(numMultiTrues, bucket.getDocCount());
assertEquals("true", bucket.getKeyAsString());
}
}
Aggregations