use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoPolygonIT method testSimpleUnclosedPolygon.
public void testSimpleUnclosedPolygon() throws Exception {
List<GeoPoint> points = new ArrayList<>();
points.add(new GeoPoint(40.7, -74.0));
points.add(new GeoPoint(40.7, -74.1));
points.add(new GeoPoint(40.8, -74.1));
points.add(new GeoPoint(40.8, -74.0));
SearchResponse searchResponse = // from NY
client().prepareSearch("test").setQuery(boolQuery().must(geoPolygonQuery("location", points))).get();
assertHitCount(searchResponse, 4);
assertThat(searchResponse.getHits().getHits().length, equalTo(4));
for (SearchHit hit : searchResponse.getHits()) {
assertThat(hit.getId(), anyOf(equalTo("1"), equalTo("3"), equalTo("4"), equalTo("5")));
}
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
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))).get();
assertSearchResponse(response);
GeoGrid grid = response.getAggregations().get("geoGrid");
assertThat(grid, notNullValue());
assertThat(grid.getName(), equalTo("geoGrid"));
List<? extends GeoGrid.Bucket> buckets = grid.getBuckets();
for (GeoGrid.Bucket cell : buckets) {
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.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoCentroidIT method testUnmapped.
public void testUnmapped() throws Exception {
SearchResponse response = client().prepareSearch(UNMAPPED_IDX_NAME).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).get();
assertSearchResponse(response);
GeoCentroid geoCentroid = response.getAggregations().get(aggName);
assertThat(geoCentroid, notNullValue());
assertThat(geoCentroid.getName(), equalTo(aggName));
GeoPoint centroid = geoCentroid.centroid();
assertThat(centroid, equalTo(null));
assertEquals(0, geoCentroid.count());
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
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)).get();
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));
assertEquals(2 * numDocs, geoCentroid.count());
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
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))).get();
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) ((InternalAggregation) 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) ((InternalAggregation) global).getProperty(aggName + ".value")).lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
assertThat(((GeoPoint) ((InternalAggregation) global).getProperty(aggName + ".value")).lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
assertThat((double) ((InternalAggregation) global).getProperty(aggName + ".lat"), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
assertThat((double) ((InternalAggregation) global).getProperty(aggName + ".lon"), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
assertEquals(numDocs, (long) ((InternalAggregation) global).getProperty(aggName + ".count"));
}
Aggregations