elastic/elasticsearch · error · IllegalArgumentException
all elements of the collection should have the same number o
Error message
all elements of the collection should have the same number of dimension
What it means
writeWKBMultiLineString (line 385) reads the first linestring's coordinates, records hasZ from it (line 400), then reads each subsequent linestring and at line 404 throws IllegalArgumentException if its hasZ differs from the first. WKB MULTILINESTRING (type 5 or 1005) is uniformly 2D or uniformly 3D per geometry; mixed-dimension components are not representable.
Source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownBinary.java:405
ByteArrayOutputStream out,
ByteBuffer scratch,
boolean explicitZ,
GeometryValidator validator
) throws IOException, ParseException {
if (WellKnownText.nextEmptyOrOpen(stream).equals(WellKnownText.EMPTY)) {
writeInt(out, scratch, 5);
writeInt(out, scratch, 0);
return;
}
List<CoordsList> lines = new ArrayList<>();
CoordsList firstLine = wktReadLineStringCoords(stream, validator);
lines.add(firstLine);
boolean hasZ = firstLine.hasZ();
while (WellKnownText.nextCloserOrComma(stream).equals(WellKnownText.COMMA)) {
CoordsList line = wktReadLineStringCoords(stream, validator);
lines.add(line);
if (line.hasZ() != hasZ) {
throw new IllegalArgumentException("all elements of the collection should have the same number of dimension");
}
}
WellKnownText.checkZorMAttribute(explicitZ, hasZ);
writeInt(out, scratch, hasZ ? 1005 : 5);
writeInt(out, scratch, lines.size());
byte byteOrderByte = (byte) (scratch.order() == ByteOrder.BIG_ENDIAN ? 0 : 1);
for (CoordsList line : lines) {
out.write(byteOrderByte);
writeInt(out, scratch, hasZ ? 1002 : 2);
writeInt(out, scratch, line.size());
writeCoordinateList(out, scratch, line);
}
}
private static void writeWKBMultiPolygon(
StreamTokenizer stream,
ByteArrayOutputStream out,
ByteBuffer scratch,View on GitHub (pinned to db6a809a66)
Solutions
- Normalize dimensionality across all linestrings in the MULTILINESTRING: drop Z from all or add Z (e.g. 0) to all.
- Split a mixed-dimension MULTILINESTRING into separate homogeneous geometries.
- Validate per-component hasZ before fromWKT and reject or normalize upstream.
Example fix
// before — mixed
fromWKT("MULTILINESTRING((0 0, 1 1), (2 2 2, 3 3 3))", BO, false, v);
// throws: all elements of the collection should have the same number of dimension
// after — all 2D
fromWKT("MULTILINESTRING((0 0, 1 1), (2 2, 3 3))", BO, false, v); Defensive patterns
Strategy: validation
Validate before calling
boolean componentsUniformZ(List<boolean> compHasZ) {
Boolean first = null;
for (boolean z : compHasZ) {
if (first == null) first = z;
else if (z != first) return false;
}
return true;
} Type guard
static boolean multiLineUniformZ(MultiLine ml) {
boolean first = ml.isEmpty() ? false : ml.get(0).hasZ();
for (Line l : ml) if (l.hasZ() != first) return false;
return true;
} Try / catch
try {
return WellKnownBinary.fromWKT(wkt, bo, coerce, v);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("same number of dimension")) {
// normalize Z across linestrings, then retry
} else throw e;
} Prevention
- Normalize Z across all linestrings in a MULTILINESTRING before fromWKT.
- Split mixed-dimension multi-geometries into homogeneous ones at ingest.
- Add a uniform-dimension validator to your ETL pre-checks.
When it happens
Trigger: Calling WellKnownBinary.fromWKT with a MULTILINESTRING WKT where some linestrings have Z and others do not, e.g. 'MULTILINESTRING((0 0, 1 1), (2 2 2, 3 3 3))'. Triggered during direct WKT-to-WKB conversion only.
Common situations: Combining linestring data from heterogeneous sources (some GPS tracks with elevation, some without). Authoring tools that conditionally emit Z. ETL pipelines that union linestrings without dimension normalization.
Related errors
- holes must have the same number of dimensions as the polygon
- Unknown geometry type:
- Empty POINT cannot be represented in WKB
- maximum nested depth of
- Empty CIRCLE cannot be represented in WKB
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/9c823d29e028e5df.
Report an issue: GitHub.