Search in sources :

Example 1 with GeoCentroid

use of org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid in project elasticsearch by elastic.

the class MissingValueIT method testGeoCentroid.

public void testGeoCentroid() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(geoCentroid("centroid").field("location").missing("2,1")).get();
    assertSearchResponse(response);
    GeoCentroid centroid = response.getAggregations().get("centroid");
    GeoPoint point = new GeoPoint(1.5, 1.5);
    assertThat(point.lat(), closeTo(centroid.centroid().lat(), 1E-5));
    assertThat(point.lon(), closeTo(centroid.centroid().lon(), 1E-5));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with GeoCentroid

use of org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid 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 3 with GeoCentroid

use of org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid in project elasticsearch by elastic.

the class GeoCentroidIT method testEmptyAggregation.

public void testEmptyAggregation() throws Exception {
    SearchResponse response = client().prepareSearch(EMPTY_IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid, equalTo(null));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 4 with GeoCentroid

use of org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid in project elasticsearch by elastic.

the class GeoCentroidIT method testSingleValuedField.

public void testSingleValuedField() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid.lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(centroid.lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 5 with GeoCentroid

use of org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid in project elasticsearch by elastic.

the class GeoCentroidIT method testUnmapped.

public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(UNMAPPED_IDX_NAME).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid, equalTo(null));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)8 GeoPoint (org.elasticsearch.common.geo.GeoPoint)8 GeoCentroid (org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid)8 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)8 GeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)1 Global (org.elasticsearch.search.aggregations.bucket.global.Global)1