Search in sources :

Example 11 with GeoBounds

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

the class GeoBoundsIT method testSingleValuedFieldAsSubAggToHighCardTermsAgg.

/**
     * This test forces the {@link GeoBoundsAggregator} to resize the {@link BigArray}s it uses to ensure they are resized correctly
     */
public void testSingleValuedFieldAsSubAggToHighCardTermsAgg() {
    SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addAggregation(terms("terms").field(NUMBER_FIELD_NAME).subAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    List<Bucket> buckets = terms.getBuckets();
    assertThat(buckets.size(), equalTo(10));
    for (int i = 0; i < 10; i++) {
        Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat("InternalBucket " + bucket.getKey() + " has wrong number of documents", bucket.getDocCount(), equalTo(1L));
        GeoBounds geoBounds = bucket.getAggregations().get(aggName);
        assertThat(geoBounds, notNullValue());
        assertThat(geoBounds.getName(), equalTo(aggName));
        assertThat(geoBounds.topLeft().getLat(), allOf(greaterThanOrEqualTo(-90.0), lessThanOrEqualTo(90.0)));
        assertThat(geoBounds.topLeft().getLon(), allOf(greaterThanOrEqualTo(-180.0), lessThanOrEqualTo(180.0)));
        assertThat(geoBounds.bottomRight().getLat(), allOf(greaterThanOrEqualTo(-90.0), lessThanOrEqualTo(90.0)));
        assertThat(geoBounds.bottomRight().getLon(), allOf(greaterThanOrEqualTo(-180.0), lessThanOrEqualTo(180.0)));
    }
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) 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 12 with GeoBounds

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

the class MissingValueIT method testUnmappedGeoBounds.

public void testUnmappedGeoBounds() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(geoBounds("bounds").field("non_existing_field").missing("2,1")).get();
    assertSearchResponse(response);
    GeoBounds bounds = response.getAggregations().get("bounds");
    assertThat(bounds.bottomRight().lat(), closeTo(2.0, 1E-5));
    assertThat(bounds.bottomRight().lon(), closeTo(1.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)

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