Search in sources :

Example 1 with GeoBounds

use of org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds in project elasticsearch by elastic.

the class MissingValueIT method testGeoBounds.

public void testGeoBounds() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(geoBounds("bounds").field("location").missing("2,1")).get();
    assertSearchResponse(response);
    GeoBounds bounds = response.getAggregations().get("bounds");
    assertThat(bounds.bottomRight().lat(), closeTo(1.0, 1E-5));
    assertThat(bounds.bottomRight().lon(), closeTo(2.0, 1E-5));
    assertThat(bounds.topLeft().lat(), closeTo(2.0, 1E-5));
    assertThat(bounds.topLeft().lon(), closeTo(1.0, 1E-5));
}
Also used : GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with GeoBounds

use of org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds in project elasticsearch by elastic.

the class GeoBoundsIT method testEmptyAggregation.

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

Example 3 with GeoBounds

use of org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds in project elasticsearch by elastic.

the class GeoBoundsIT method testSingleValuedFieldNearDateLineWrapLongitude.

public void testSingleValuedFieldNearDateLineWrapLongitude() throws Exception {
    GeoPoint geoValuesTopLeft = new GeoPoint(38, 170);
    GeoPoint geoValuesBottomRight = new GeoPoint(-24, -175);
    SearchResponse response = client().prepareSearch(DATELINE_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(true)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(geoValuesTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(geoValuesTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(geoValuesBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(geoValuesBottomRight.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 4 with GeoBounds

use of org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds in project elasticsearch by elastic.

the class GeoBoundsIT method testSingleValuedFieldWithZeroLon.

public void testSingleValuedFieldWithZeroLon() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_ZERO_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 5 with GeoBounds

use of org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds in project elasticsearch by elastic.

the class GeoBoundsIT method testSingleValuedFieldNearDateLine.

public void testSingleValuedFieldNearDateLine() throws Exception {
    SearchResponse response = client().prepareSearch(DATELINE_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoPoint geoValuesTopLeft = new GeoPoint(38, -179);
    GeoPoint geoValuesBottomRight = new GeoPoint(-24, 178);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(geoValuesTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(geoValuesTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(geoValuesBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(geoValuesBottomRight.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)12 GeoBounds (org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds)12 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)12 GeoPoint (org.elasticsearch.common.geo.GeoPoint)10 Global (org.elasticsearch.search.aggregations.bucket.global.Global)1 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)1 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)1