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

  1. Filter out empty/null geohashes before calling mortonEncode or its dependents.
  2. Treat empty geohash as missing data and skip the record (or use a sentinel/default location).
  3. 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

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


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/f92a8df835630589. Report an issue: GitHub.