Search in sources :

Example 6 with GeoCentroid

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

the class GeoCentroidIT method testMultiValuedField.

public void testMultiValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoCentroid(aggName).field(MULTI_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(searchResponse);
    GeoCentroid geoCentroid = searchResponse.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid.lat(), closeTo(multiCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(centroid.lon(), closeTo(multiCentroid.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 7 with GeoCentroid

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

the class GeoCentroidIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME, 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.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 8 with GeoCentroid

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

the class GeoCentroidIT method testSingleValueFieldGetProperty.

public void testSingleValueFieldGetProperty() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME))).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(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    GeoCentroid geoCentroid = global.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    assertThat((GeoCentroid) global.getProperty(aggName), sameInstance(geoCentroid));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid.lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(centroid.lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
    assertThat(((GeoPoint) global.getProperty(aggName + ".value")).lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(((GeoPoint) global.getProperty(aggName + ".value")).lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".lat"), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".lon"), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) Global(org.elasticsearch.search.aggregations.bucket.global.Global) 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