Search in sources :

Example 6 with GeoBounds

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

the class GeoBoundsIT method testUnmapped.

public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(UNMAPPED_IDX_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, 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 7 with GeoBounds

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

the class GeoBoundsIT method testMultiValuedField.

public void testMultiValuedField() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME).addAggregation(geoBounds(aggName).field(MULTI_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(multiTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(multiTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(multiBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(multiBottomRight.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 8 with GeoBounds

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

the class GeoBoundsIT method testSingleValuedField.

public void testSingleValuedField() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_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(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.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 9 with GeoBounds

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

the class GeoBoundsIT method testSingleValuedField_getProperty.

public void testSingleValuedField_getProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false))).execute().actionGet();
    assertSearchResponse(searchResponse);
    Global global = searchResponse.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));
    GeoBounds geobounds = global.getAggregations().get(aggName);
    assertThat(geobounds, notNullValue());
    assertThat(geobounds.getName(), equalTo(aggName));
    assertThat((GeoBounds) global.getProperty(aggName), sameInstance(geobounds));
    GeoPoint topLeft = geobounds.topLeft();
    GeoPoint bottomRight = geobounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".top"), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".left"), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".bottom"), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".right"), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) Global(org.elasticsearch.search.aggregations.bucket.global.Global) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 10 with GeoBounds

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

the class GeoBoundsIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME, UNMAPPED_IDX_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(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.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