Search in sources :

Example 1 with GeoBoundingBoxQueryBuilder

use of org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder in project elasticsearch by elastic.

the class GeoHashGridIT method testFiltered.

public void testFiltered() throws Exception {
    GeoBoundingBoxQueryBuilder bbox = new GeoBoundingBoxQueryBuilder("location");
    bbox.setCorners(smallestGeoHash).queryName("bbox");
    for (int precision = 1; precision <= PRECISION; precision++) {
        SearchResponse response = client().prepareSearch("idx").addAggregation(AggregationBuilders.filter("filtered", bbox).subAggregation(geohashGrid("geohashgrid").field("location").precision(precision))).execute().actionGet();
        assertSearchResponse(response);
        Filter filter = response.getAggregations().get("filtered");
        GeoHashGrid geoGrid = filter.getAggregations().get("geohashgrid");
        for (GeoHashGrid.Bucket cell : geoGrid.getBuckets()) {
            String geohash = cell.getKeyAsString();
            long bucketCount = cell.getDocCount();
            int expectedBucketCount = expectedDocCountsForGeoHash.get(geohash);
            assertNotSame(bucketCount, 0);
            assertTrue("Buckets must be filtered", geohash.startsWith(smallestGeoHash));
            assertEquals("Geohash " + geohash + " has wrong doc count ", expectedBucketCount, bucketCount);
        }
    }
}
Also used : GeoBoundingBoxQueryBuilder(org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Bucket(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid.Bucket) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoPoint(org.elasticsearch.common.geo.GeoPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)1 GeoPoint (org.elasticsearch.common.geo.GeoPoint)1 GeoBoundingBoxQueryBuilder (org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder)1 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)1 GeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)1 Bucket (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid.Bucket)1 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1