Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/reference/migration/migrate_7_0/aggregations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ Aggregation is now a variable called `state` available in the script context, ra
being provided via the `params` object as `params._agg`.

The old `params._agg` variable is still available as well.

==== Change GeoHashGrid.Bucket#getKey() to return a String instead of a GeoPoint

The aggregation bucket used to return a GeoPoint representing the bucket keys hash
value. This was not consistent with the Rest API output that represents the key simply
as the string value of the geohash. The Java API now also returns a String here which
can be converted to a point as needed by the client.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static long longEncode(final String hash, int length) {
long b;
long l = 0L;
for(char c : hash.toCharArray()) {
b = (long)(BASE_32_STRING.indexOf(c));
b = BASE_32_STRING.indexOf(c);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My IDE made me do it ;-) Can revert if it is confusing in this PR.

l |= (b<<(level--*5));
if (level < 0) {
// We cannot handle more than 12 levels
Expand Down Expand Up @@ -178,7 +178,7 @@ public static final long mortonEncode(final String hash) {
long b;
long l = 0L;
for(char c : hash.toCharArray()) {
b = (long)(BASE_32_STRING.indexOf(c));
b = BASE_32_STRING.indexOf(c);
if (b < 0) {
throw new IllegalArgumentException("unsupported symbol [" + c + "] in geohash [" + hash + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.lucene.util.PriorityQueue;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.LongObjectPagedHashMap;
Expand Down Expand Up @@ -77,12 +76,12 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public String getKeyAsString() {
return GeoHashUtils.stringEncode(geohashAsLong);
return getKey();
}

@Override
public GeoPoint getKey() {
return GeoPoint.fromGeohash(geohashAsLong);
public String getKey() {
return GeoHashUtils.stringEncode(geohashAsLong);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

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

import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
Expand Down Expand Up @@ -57,8 +56,8 @@ public static class ParsedBucket extends ParsedMultiBucketAggregation.ParsedBuck
private String geohashAsString;

@Override
public GeoPoint getKey() {
return GeoPoint.fromGeohash(geohashAsString);
public String getKey() {
return geohashAsString;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder;
Expand Down Expand Up @@ -171,8 +170,8 @@ public void testSimple() throws Exception {
assertNotSame(bucketCount, 0);
assertEquals("Geohash " + geohash + " has wrong doc count ",
expectedBucketCount, bucketCount);
GeoPoint geoPoint = (GeoPoint) propertiesKeys[i];
assertThat(stringEncode(geoPoint.lon(), geoPoint.lat(), precision), equalTo(geohash));
String parsedGeoHash = (String) propertiesKeys[i];
assertThat(parsedGeoHash, equalTo(geohash));
assertThat((long) propertiesDocCounts[i], equalTo(bucketCount));
}
}
Expand Down