-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support cartesian_bounds aggregation on point and shape #91298
Changes from 9 commits
2af3c58
21d7a72
50ddaed
f94ee9c
28e917c
e4317ae
794cb53
d40ba6e
596ee0d
5b2f9e5
4194cf0
84cc481
bb5ad2d
ee930e6
2b502c1
c5ff54e
f0c9ea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 91298 | ||
summary: Support `cartesian_bounds` aggregation on point and shape | ||
area: Geo | ||
type: enhancement | ||
issues: | ||
- 90157 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,18 @@ | |
|
||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.common.geo.GeoPoint; | ||
import org.elasticsearch.common.geo.SpatialPoint; | ||
import org.elasticsearch.common.util.BigArray; | ||
import org.elasticsearch.search.aggregations.InternalAggregation; | ||
import org.elasticsearch.search.aggregations.bucket.global.Global; | ||
import org.elasticsearch.search.aggregations.bucket.terms.Terms; | ||
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.geo.RandomGeoGenerator; | ||
|
||
import java.util.List; | ||
|
||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; | ||
import static org.elasticsearch.search.aggregations.AggregationBuilders.geoBounds; | ||
import static org.elasticsearch.search.aggregations.AggregationBuilders.global; | ||
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; | ||
|
@@ -43,15 +44,15 @@ public void testSingleValuedField() throws Exception { | |
|
||
assertSearchResponse(response); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> 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)); | ||
assertThat(topLeft.getY(), closeTo(singleTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(singleTopLeft.getX(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(singleBottomRight.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(singleBottomRight.getX(), GEOHASH_TOLERANCE)); | ||
} | ||
|
||
public void testSingleValuedField_getProperty() throws Exception { | ||
|
@@ -69,25 +70,28 @@ public void testSingleValuedField_getProperty() throws Exception { | |
assertThat(global.getAggregations(), notNullValue()); | ||
assertThat(global.getAggregations().asMap().size(), equalTo(1)); | ||
|
||
GeoBounds geobounds = global.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> geobounds = global.getAggregations().get(aggName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've done this for the two dateline tests, but all the rest moved into shared code. |
||
assertThat(geobounds, notNullValue()); | ||
assertThat(geobounds.getName(), equalTo(aggName)); | ||
assertThat((GeoBounds) ((InternalAggregation) global).getProperty(aggName), sameInstance(geobounds)); | ||
assertThat((SpatialBounds<?>) ((InternalAggregation) 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) ((InternalAggregation) global).getProperty(aggName + ".top"), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE)); | ||
assertThat((double) ((InternalAggregation) global).getProperty(aggName + ".left"), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getY(), closeTo(singleTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(singleTopLeft.getX(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(singleBottomRight.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(singleBottomRight.getX(), GEOHASH_TOLERANCE)); | ||
assertThat((double) ((InternalAggregation) global).getProperty(aggName + ".top"), closeTo(singleTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat( | ||
(double) ((InternalAggregation) global).getProperty(aggName + ".left"), | ||
closeTo(singleTopLeft.getX(), GEOHASH_TOLERANCE) | ||
); | ||
assertThat( | ||
(double) ((InternalAggregation) global).getProperty(aggName + ".bottom"), | ||
closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE) | ||
closeTo(singleBottomRight.getY(), GEOHASH_TOLERANCE) | ||
); | ||
assertThat( | ||
(double) ((InternalAggregation) global).getProperty(aggName + ".right"), | ||
closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE) | ||
closeTo(singleBottomRight.getX(), GEOHASH_TOLERANCE) | ||
); | ||
} | ||
|
||
|
@@ -98,15 +102,15 @@ public void testMultiValuedField() throws Exception { | |
|
||
assertSearchResponse(response); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> geoBounds = response.getAggregations().get(aggName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here, and every place where we know the concrete class |
||
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)); | ||
assertThat(topLeft.getY(), closeTo(multiTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(multiTopLeft.getX(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(multiBottomRight.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(multiBottomRight.getX(), GEOHASH_TOLERANCE)); | ||
} | ||
|
||
public void testUnmapped() throws Exception { | ||
|
@@ -116,7 +120,7 @@ public void testUnmapped() throws Exception { | |
|
||
assertSearchResponse(response); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> geoBounds = response.getAggregations().get(aggName); | ||
assertThat(geoBounds, notNullValue()); | ||
assertThat(geoBounds.getName(), equalTo(aggName)); | ||
GeoPoint topLeft = geoBounds.topLeft(); | ||
|
@@ -132,15 +136,15 @@ public void testPartiallyUnmapped() throws Exception { | |
|
||
assertSearchResponse(response); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> 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)); | ||
assertThat(topLeft.getY(), closeTo(singleTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(singleTopLeft.getX(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(singleBottomRight.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(singleBottomRight.getX(), GEOHASH_TOLERANCE)); | ||
} | ||
|
||
public void testEmptyAggregation() throws Exception { | ||
|
@@ -150,7 +154,7 @@ public void testEmptyAggregation() throws Exception { | |
.get(); | ||
|
||
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); | ||
GeoBounds geoBounds = searchResponse.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> geoBounds = searchResponse.getAggregations().get(aggName); | ||
assertThat(geoBounds, notNullValue()); | ||
assertThat(geoBounds.getName(), equalTo(aggName)); | ||
GeoPoint topLeft = geoBounds.topLeft(); | ||
|
@@ -169,15 +173,15 @@ public void testSingleValuedFieldNearDateLine() throws Exception { | |
GeoPoint geoValuesTopLeft = new GeoPoint(38, -179); | ||
GeoPoint geoValuesBottomRight = new GeoPoint(-24, 178); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> 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)); | ||
assertThat(topLeft.getY(), closeTo(geoValuesTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(geoValuesTopLeft.getX(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(geoValuesBottomRight.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(geoValuesBottomRight.getX(), GEOHASH_TOLERANCE)); | ||
} | ||
|
||
public void testSingleValuedFieldNearDateLineWrapLongitude() throws Exception { | ||
|
@@ -190,15 +194,15 @@ public void testSingleValuedFieldNearDateLineWrapLongitude() throws Exception { | |
|
||
assertSearchResponse(response); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> 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)); | ||
assertThat(topLeft.getY(), closeTo(geoValuesTopLeft.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(geoValuesTopLeft.getX(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(geoValuesBottomRight.getY(), GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(geoValuesBottomRight.getX(), GEOHASH_TOLERANCE)); | ||
} | ||
|
||
/** | ||
|
@@ -223,7 +227,7 @@ public void testSingleValuedFieldAsSubAggToHighCardTermsAgg() { | |
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); | ||
SpatialBounds<GeoPoint> geoBounds = bucket.getAggregations().get(aggName); | ||
assertThat(geoBounds, notNullValue()); | ||
assertThat(geoBounds.getName(), equalTo(aggName)); | ||
assertThat(geoBounds.topLeft().getLat(), allOf(greaterThanOrEqualTo(-90.0), lessThanOrEqualTo(90.0))); | ||
|
@@ -240,14 +244,48 @@ public void testSingleValuedFieldWithZeroLon() throws Exception { | |
|
||
assertSearchResponse(response); | ||
|
||
GeoBounds geoBounds = response.getAggregations().get(aggName); | ||
SpatialBounds<GeoPoint> 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(1.0, GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.lon(), closeTo(0.0, GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.lat(), closeTo(1.0, GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.lon(), closeTo(0.0, GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getY(), closeTo(1.0, GEOHASH_TOLERANCE)); | ||
assertThat(topLeft.getX(), closeTo(0.0, GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getY(), closeTo(1.0, GEOHASH_TOLERANCE)); | ||
assertThat(bottomRight.getX(), closeTo(0.0, GEOHASH_TOLERANCE)); | ||
} | ||
|
||
public static GeoBoundsAggregationBuilder geoBounds(String name) { | ||
return new GeoBoundsAggregationBuilder(name); | ||
} | ||
|
||
@Override | ||
protected String fieldTypeName() { | ||
return "geo_point"; | ||
} | ||
|
||
@Override | ||
protected GeoPoint makePoint(double x, double y) { | ||
return new GeoPoint(y, x); | ||
} | ||
|
||
@Override | ||
protected GeoPoint randomPoint() { | ||
return RandomGeoGenerator.randomPoint(random()); | ||
} | ||
|
||
@Override | ||
protected void resetX(SpatialPoint point, double x) { | ||
((GeoPoint) point).resetLon(x); | ||
} | ||
|
||
@Override | ||
protected void resetY(SpatialPoint point, double y) { | ||
((GeoPoint) point).resetLat(y); | ||
} | ||
|
||
@Override | ||
protected GeoPoint reset(SpatialPoint point, double x, double y) { | ||
return ((GeoPoint) point).reset(y, x); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be use here GeoBounds instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was in the process of refactoring. I'll finish the job and then you can decide.