diff --git a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java index 7bb4d6c889623..189b277a260f5 100644 --- a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java +++ b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java @@ -10,6 +10,7 @@ import com.carrotsearch.hppc.ObjectIntHashMap; import com.carrotsearch.hppc.ObjectIntMap; +import org.apache.lucene.geo.GeoEncodingUtils; import org.opensearch.Version; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.cluster.metadata.IndexMetadata; @@ -254,4 +255,17 @@ protected double getRadiusOfBoundingBox() { return 5.0; } + /** + * Encode and Decode the {@link GeoPoint} to get a {@link GeoPoint} which has the exact precision which is being + * stored. + * @param geoPoint {@link GeoPoint} + * @return {@link GeoPoint} + */ + protected GeoPoint toStoragePrecision(final GeoPoint geoPoint) { + return new GeoPoint( + GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(geoPoint.getLat())), + GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(geoPoint.getLon())) + ); + } + } diff --git a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java index 269dc52f29317..4c2c13b66d926 100644 --- a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java +++ b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java @@ -160,7 +160,8 @@ protected Set generateBucketsForGeometry(final Geometry geometry, final protected Set generateBucketsForGeoPoint(final GeoPoint geoPoint) { Set buckets = new HashSet<>(); for (int precision = GEOPOINT_MAX_PRECISION; precision > 0; precision--) { - final String tile = GeoTileUtils.stringEncode(geoPoint.getLon(), geoPoint.getLat(), precision); + final GeoPoint precisedGeoPoint = this.toStoragePrecision(geoPoint); + final String tile = GeoTileUtils.stringEncode(precisedGeoPoint.getLon(), precisedGeoPoint.getLat(), precision); buckets.add(tile); } return buckets;