Search in sources :

Example 1 with GeoHashGrid

use of org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid 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));
    }
}
Also used : GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid) GeoPoint(org.elasticsearch.common.geo.GeoPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with GeoHashGrid

use of org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid 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);
        }
    }
}
Also used : 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)

Example 3 with GeoHashGrid

use of org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid in project elasticsearch by elastic.

the class ShardReduceIT method testGeoHashGrid.

public void testGeoHashGrid() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(geohashGrid("grid").field("location").subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
    assertSearchResponse(response);
    GeoHashGrid grid = response.getAggregations().get("grid");
    Histogram histo = grid.getBuckets().iterator().next().getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 4 with GeoHashGrid

use of org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid in project elasticsearch by elastic.

the class GeoCentroidIT method testSingleValueFieldAsSubAggToGeohashGrid.

public void testSingleValueFieldAsSubAggToGeohashGrid() throws Exception {
    SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addAggregation(geohashGrid("geoGrid").field(SINGLE_VALUED_FIELD_NAME).subAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME))).execute().actionGet();
    assertSearchResponse(response);
    GeoHashGrid grid = response.getAggregations().get("geoGrid");
    assertThat(grid, notNullValue());
    assertThat(grid.getName(), equalTo("geoGrid"));
    List<GeoHashGrid.Bucket> buckets = grid.getBuckets();
    for (int i = 0; i < buckets.size(); ++i) {
        GeoHashGrid.Bucket cell = buckets.get(i);
        String geohash = cell.getKeyAsString();
        GeoPoint expectedCentroid = expectedCentroidsForGeoHash.get(geohash);
        GeoCentroid centroidAgg = cell.getAggregations().get(aggName);
        assertThat("Geohash " + geohash + " has wrong centroid latitude ", expectedCentroid.lat(), closeTo(centroidAgg.centroid().lat(), GEOHASH_TOLERANCE));
        assertThat("Geohash " + geohash + " has wrong centroid longitude", expectedCentroid.lon(), closeTo(centroidAgg.centroid().lon(), GEOHASH_TOLERANCE));
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid) GeoPoint(org.elasticsearch.common.geo.GeoPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 5 with GeoHashGrid

use of org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid in project elasticsearch by elastic.

the class GeoHashGridIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    for (int precision = 1; precision <= PRECISION; precision++) {
        SearchResponse response = client().prepareSearch("idx", "idx_unmapped").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 = expectedDocCountsForGeoHash.get(geohash);
            assertNotSame(bucketCount, 0);
            assertEquals("Geohash " + geohash + " has wrong doc count ", expectedBucketCount, bucketCount);
        }
    }
}
Also used : 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

GeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)8 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)8 GeoPoint (org.elasticsearch.common.geo.GeoPoint)7 Bucket (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid.Bucket)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 GeoBoundingBoxQueryBuilder (org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder)1 Aggregation (org.elasticsearch.search.aggregations.Aggregation)1 AggregationBuilders.dateHistogram (org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram)1 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)1 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)1 InternalGeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid)1 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)1 GeoCentroid (org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid)1 VertexiumException (org.vertexium.VertexiumException)1 GeoPoint (org.vertexium.type.GeoPoint)1 GeoRect (org.vertexium.type.GeoRect)1