Search in sources :

Example 1 with GeoBoundingBoxQueryBuilder

use of org.opensearch.index.query.GeoBoundingBoxQueryBuilder in project OpenSearch by opensearch-project.

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))).get();
        assertSearchResponse(response);
        Filter filter = response.getAggregations().get("filtered");
        GeoGrid geoGrid = filter.getAggregations().get("geohashgrid");
        for (GeoGrid.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.opensearch.index.query.GeoBoundingBoxQueryBuilder) Bucket(org.opensearch.search.aggregations.bucket.geogrid.GeoGrid.Bucket) Filter(org.opensearch.search.aggregations.bucket.filter.Filter) GeoGrid(org.opensearch.search.aggregations.bucket.geogrid.GeoGrid) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

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