use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class AbstractGeoTestCase method updateHashCentroid.
private GeoPoint updateHashCentroid(String hash, final GeoPoint location) {
GeoPoint centroid = expectedCentroidsForGeoHash.getOrDefault(hash, null);
if (centroid == null) {
return new GeoPoint(location.lat(), location.lon());
}
final int docCount = expectedDocCountsForGeoHash.get(hash);
final double newLon = centroid.lon() + (location.lon() - centroid.lon()) / docCount;
final double newLat = centroid.lat() + (location.lat() - centroid.lat()) / docCount;
return centroid.reset(newLat, newLon);
}
use of org.elasticsearch.common.geo.GeoPoint 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));
}
use of org.elasticsearch.common.geo.GeoPoint 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));
}
use of org.elasticsearch.common.geo.GeoPoint 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));
}
}
use of org.elasticsearch.common.geo.GeoPoint 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));
}
Aggregations