Skip to content

Commit 0349b62

Browse files
author
Christoph Büscher
committed
Change GeoHashGrid.Bucket#getKey() to return String
The GeoHashGrid bucket class currently returns a GeoPoint with its getKey() method. The REST API returns geohash as a String in the key field of the bucket. This changes the getKey() method to also return a String. Having the ability to get a GeoPoint from a bucket that represents a geohash cell is misleading because the cell does not represent a point but an area. Instead, it should be the clients responsibility to make the decision on how to represent the bucket key in its application. This also simplifies implementing the high level rest client aspects of #30320, as the client will not need to know about the GeoHashType being used and will only care that there is some string key for the buckets. Relates to #30320
1 parent 2971dd5 commit 0349b62

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

docs/reference/migration/migrate_7_0/aggregations.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ Aggregation is now a variable called `state` available in the script context, ra
2323
being provided via the `params` object as `params._agg`.
2424

2525
The old `params._agg` variable is still available as well.
26+
27+
==== Change GeoHashGrid.Bucket#getKey() to return a String instead of a GeoPoint
28+
29+
The aggregation bucket used to return a GeoPoint representing the bucket keys hash
30+
value. This was not consistent with the Rest API output that represents the key simply
31+
as the string value of the geohash. The Java API now also returns a String here which
32+
can be converted to a point as needed by the client.

server/src/main/java/org/elasticsearch/common/geo/GeoHashUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static long longEncode(final String hash, int length) {
7777
long b;
7878
long l = 0L;
7979
for(char c : hash.toCharArray()) {
80-
b = (long)(BASE_32_STRING.indexOf(c));
80+
b = BASE_32_STRING.indexOf(c);
8181
l |= (b<<(level--*5));
8282
if (level < 0) {
8383
// We cannot handle more than 12 levels
@@ -178,7 +178,7 @@ public static final long mortonEncode(final String hash) {
178178
long b;
179179
long l = 0L;
180180
for(char c : hash.toCharArray()) {
181-
b = (long)(BASE_32_STRING.indexOf(c));
181+
b = BASE_32_STRING.indexOf(c);
182182
if (b < 0) {
183183
throw new IllegalArgumentException("unsupported symbol [" + c + "] in geohash [" + hash + "]");
184184
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.apache.lucene.util.PriorityQueue;
2222
import org.elasticsearch.common.geo.GeoHashUtils;
23-
import org.elasticsearch.common.geo.GeoPoint;
2423
import org.elasticsearch.common.io.stream.StreamInput;
2524
import org.elasticsearch.common.io.stream.StreamOutput;
2625
import org.elasticsearch.common.util.LongObjectPagedHashMap;
@@ -77,12 +76,12 @@ public void writeTo(StreamOutput out) throws IOException {
7776

7877
@Override
7978
public String getKeyAsString() {
80-
return GeoHashUtils.stringEncode(geohashAsLong);
79+
return getKey();
8180
}
8281

8382
@Override
84-
public GeoPoint getKey() {
85-
return GeoPoint.fromGeohash(geohashAsLong);
83+
public String getKey() {
84+
return GeoHashUtils.stringEncode(geohashAsLong);
8685
}
8786

8887
@Override

server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/ParsedGeoHashGrid.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.search.aggregations.bucket.geogrid;
2121

22-
import org.elasticsearch.common.geo.GeoPoint;
2322
import org.elasticsearch.common.xcontent.ObjectParser;
2423
import org.elasticsearch.common.xcontent.XContentBuilder;
2524
import org.elasticsearch.common.xcontent.XContentParser;
@@ -57,8 +56,8 @@ public static class ParsedBucket extends ParsedMultiBucketAggregation.ParsedBuck
5756
private String geohashAsString;
5857

5958
@Override
60-
public GeoPoint getKey() {
61-
return GeoPoint.fromGeohash(geohashAsString);
59+
public String getKey() {
60+
return geohashAsString;
6261
}
6362

6463
@Override

0 commit comments

Comments
 (0)