elastic/elasticsearch · error · IllegalArgumentException
empty geohash
Error message
empty geohash
What it means
Thrown by Geohash.mortonEncode(String) when the input geohash string is empty. An empty geohash encodes no spatial information, so the method rejects it immediately rather than returning a default morton code. The check runs before any character processing.
Source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/utils/Geohash.java:324
long b;
long l = 0L;
for (char c : hash.toCharArray()) {
b = (long) (BASE_32_STRING.indexOf(c));
l |= (b << (level-- * 5));
if (level < 0) {
// We cannot handle more than 12 levels
break;
}
}
return (l << 4) | length;
}
/**
* Encode to a morton long value from a given geohash string
*/
public static long mortonEncode(final String hash) {
if (hash.isEmpty()) {
throw new IllegalArgumentException("empty geohash");
}
int level = 11;
long b;
long l = 0L;
for (char c : hash.toCharArray()) {
b = (long) (BASE_32_STRING.indexOf(c));
if (b < 0) {
throw new IllegalArgumentException("unsupported symbol [" + c + "] in geohash [" + hash + "]");
}
l |= (b << ((level-- * 5) + (MORTON_OFFSET - 2)));
if (level < 0) {
// We cannot handle more than 12 levels
break;
}
}
return BitUtil.flipFlop(l);
}
View on GitHub (pinned to db6a809a66)
Solutions
- Filter out empty/null geohashes before calling mortonEncode or its dependents.
- Treat empty geohash as missing data and skip the record (or use a sentinel/default location).
- Validate the input string is non-empty after trimming at the ingestion boundary.
Example fix
// before
long m = Geohash.mortonEncode(hash); // throws if hash.isEmpty()
// after
if (hash == null || hash.isBlank()) {
return; // or handle as missing
}
long m = Geohash.mortonEncode(hash); Defensive patterns
Strategy: validation
Validate before calling
if (hash == null || hash.isEmpty()) {
throw new IllegalArgumentException("geohash missing"); // or skip the record
}
return Geohash.mortonEncode(hash); Type guard
static boolean isNonEmptyGeohash(String hash) {
return hash != null && !hash.isEmpty();
} Prevention
- Treat null and empty geohash as missing data at ingestion.
- Validate non-empty after trimming at the trust boundary.
- Do not coalesce null to "" — skip the record instead.
When it happens
Trigger: Calling `Geohash.mortonEncode("")`, or any higher-level API that delegates to it (Geohash.toPoint, Geohash.toBoundingBox) with an empty string.
Common situations: Missing/blank geohash field in source documents; string trimming that reduced a whitespace value to empty; null-coalescing that turned null into "" instead of rejecting; upstream filter that allowed empty strings through.
Related errors
- unsupported symbol [
- max y cannot be less than min y
- only one z value is specified
- max x cannot be less than min x
- invalid latitude
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/f92a8df835630589.
Report an issue: GitHub.