Skip to content

Commit 213487f

Browse files
committed
test fix
1 parent 2aa2fb1 commit 213487f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.elasticsearch.search.aggregations.bucket.geogrid;
2020

2121
import org.apache.lucene.document.LatLonDocValuesField;
22+
import org.apache.lucene.geo.GeoEncodingUtils;
2223
import org.apache.lucene.index.DirectoryReader;
2324
import org.apache.lucene.index.IndexReader;
2425
import org.apache.lucene.index.RandomIndexWriter;
@@ -77,6 +78,11 @@ private void testWithSeveralDocs(GeoHashType type, int precision)
7778
for (int pointId = 0; pointId < numPoints; pointId++) {
7879
double lat = (180d * randomDouble()) - 90d;
7980
double lng = (360d * randomDouble()) - 180d;
81+
82+
// Precision-adjust longitude/latitude to avoid wrong bucket placement
83+
lng = GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lng));
84+
lat = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));
85+
8086
points.add(new LatLonDocValuesField(FIELD_NAME, lat, lng));
8187
String hash = type.getHandler().hashAsString(type.getHandler().calculateHash(lng, lat, precision));
8288
if (distinctHashesPerDoc.contains(hash) == false) {

0 commit comments

Comments
 (0)