use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class QueryDSLDocumentationTests method testGeoPolygon.
public void testGeoPolygon() {
// tag::geo_polygon
// <1>
List<GeoPoint> points = new ArrayList<>();
points.add(new GeoPoint(40, -70));
points.add(new GeoPoint(30, -80));
points.add(new GeoPoint(20, -90));
// <2>
geoPolygonQuery("pin.location", points);
// end::geo_polygon
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoHashTests method testGeohashAsLongRoutines.
public void testGeohashAsLongRoutines() {
final GeoPoint expected = new GeoPoint();
final GeoPoint actual = new GeoPoint();
// String based counterpart
for (double lat = -90; lat < 90; lat++) {
for (double lng = -180; lng < 180; lng++) {
for (int p = 1; p <= 12; p++) {
long geoAsLong = Geohash.longEncode(lng, lat, p);
// string encode from geohashlong encoded location
String geohashFromLong = Geohash.stringEncode(geoAsLong);
// string encode from full res lat lon
String geohash = Geohash.stringEncode(lng, lat, p);
// ensure both strings are the same
assertEquals(geohash, geohashFromLong);
// decode from the full-res geohash string
expected.resetFromGeoHash(geohash);
// decode from the geohash encoded long
actual.resetFromGeoHash(geoAsLong);
assertEquals(expected, actual);
}
}
}
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoDistanceIT method testSimpleWithCustomKeys.
public void testSimpleWithCustomKeys() throws Exception {
SearchResponse response = client().prepareSearch("idx").addAggregation(geoDistance("amsterdam_rings", new GeoPoint(52.3760, 4.894)).field("location").unit(DistanceUnit.KILOMETERS).addUnboundedTo("ring1", 500).addRange("ring2", 500, 1000).addUnboundedFrom("ring3", 1000)).get();
assertSearchResponse(response);
Range geoDist = response.getAggregations().get("amsterdam_rings");
assertThat(geoDist, notNullValue());
assertThat(geoDist.getName(), equalTo("amsterdam_rings"));
List<? extends Bucket> buckets = geoDist.getBuckets();
assertThat(buckets.size(), equalTo(3));
Range.Bucket bucket = buckets.get(0);
assertThat(bucket, notNullValue());
assertThat((String) bucket.getKey(), equalTo("ring1"));
assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(0.0));
assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(500.0));
assertThat(bucket.getFromAsString(), equalTo("0.0"));
assertThat(bucket.getToAsString(), equalTo("500.0"));
assertThat(bucket.getDocCount(), equalTo(2L));
bucket = buckets.get(1);
assertThat(bucket, notNullValue());
assertThat((String) bucket.getKey(), equalTo("ring2"));
assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(500.0));
assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(1000.0));
assertThat(bucket.getFromAsString(), equalTo("500.0"));
assertThat(bucket.getToAsString(), equalTo("1000.0"));
assertThat(bucket.getDocCount(), equalTo(2L));
bucket = buckets.get(2);
assertThat(bucket, notNullValue());
assertThat((String) bucket.getKey(), equalTo("ring3"));
assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(1000.0));
assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
assertThat(bucket.getFromAsString(), equalTo("1000.0"));
assertThat(bucket.getToAsString(), nullValue());
assertThat(bucket.getDocCount(), equalTo(1L));
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoDistanceIT method testEmptyAggregation.
public void testEmptyAggregation() throws Exception {
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(geoDistance("geo_dist", new GeoPoint(52.3760, 4.894)).field("location").addRange("0-100", 0.0, 100.0))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
Histogram histo = searchResponse.getAggregations().get("histo");
assertThat(histo, Matchers.notNullValue());
Histogram.Bucket bucket = histo.getBuckets().get(1);
assertThat(bucket, Matchers.notNullValue());
Range geoDistance = bucket.getAggregations().get("geo_dist");
// TODO: use diamond once JI-9019884 is fixed
List<Range.Bucket> buckets = new ArrayList<>(geoDistance.getBuckets());
assertThat(geoDistance, Matchers.notNullValue());
assertThat(geoDistance.getName(), equalTo("geo_dist"));
assertThat(buckets.size(), is(1));
assertThat((String) buckets.get(0).getKey(), equalTo("0-100"));
assertThat(((Number) buckets.get(0).getFrom()).doubleValue(), equalTo(0.0));
assertThat(((Number) buckets.get(0).getTo()).doubleValue(), equalTo(100.0));
assertThat(buckets.get(0).getFromAsString(), equalTo("0.0"));
assertThat(buckets.get(0).getToAsString(), equalTo("100.0"));
assertThat(buckets.get(0).getDocCount(), equalTo(0L));
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoDistanceIT method testPartiallyUnmapped.
public void testPartiallyUnmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx", "idx_unmapped").addAggregation(geoDistance("amsterdam_rings", new GeoPoint(52.3760, 4.894)).field("location").unit(DistanceUnit.KILOMETERS).addUnboundedTo(500).addRange(500, 1000).addUnboundedFrom(1000)).get();
assertSearchResponse(response);
Range geoDist = response.getAggregations().get("amsterdam_rings");
assertThat(geoDist, notNullValue());
assertThat(geoDist.getName(), equalTo("amsterdam_rings"));
List<? extends Bucket> buckets = geoDist.getBuckets();
assertThat(geoDist.getBuckets().size(), equalTo(3));
Range.Bucket bucket = buckets.get(0);
assertThat(bucket, notNullValue());
assertThat((String) bucket.getKey(), equalTo("*-500.0"));
assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(0.0));
assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(500.0));
assertThat(bucket.getFromAsString(), equalTo("0.0"));
assertThat(bucket.getToAsString(), equalTo("500.0"));
assertThat(bucket.getDocCount(), equalTo(2L));
bucket = buckets.get(1);
assertThat(bucket, notNullValue());
assertThat((String) bucket.getKey(), equalTo("500.0-1000.0"));
assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(500.0));
assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(1000.0));
assertThat(bucket.getFromAsString(), equalTo("500.0"));
assertThat(bucket.getToAsString(), equalTo("1000.0"));
assertThat(bucket.getDocCount(), equalTo(2L));
bucket = buckets.get(2);
assertThat(bucket, notNullValue());
assertThat((String) bucket.getKey(), equalTo("1000.0-*"));
assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(1000.0));
assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
assertThat(bucket.getFromAsString(), equalTo("1000.0"));
assertThat(bucket.getToAsString(), nullValue());
assertThat(bucket.getDocCount(), equalTo(1L));
}
Aggregations