prestodb/presto · error · PrestoException
ELASTICSEARCH_TYPE_MISMATCH
ELASTICSEARCH_TYPE_MISMATCH
Error message
Expected a numeric value for field %s of type REAL: %s [%s]
What it means
RealDecoder requires the mapped REAL (float) column's document value to be an instance of java.lang.Number; it writes floatBits via REAL.writeLong. Any non-numeric JSON value (string, boolean, object, array) raises ELASTICSEARCH_TYPE_MISMATCH. No string-to-float coercion is performed.
Source
Thrown at presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/RealDecoder.java:48
private final String path;
public RealDecoder(String path)
{
this.path = requireNonNull(path, "path is null");
}
@Override
public void decode(Hit hit, Supplier<Object> getter, BlockBuilder output)
{
Object value = getter.get();
if (value == null) {
output.appendNull();
}
else if (value instanceof Number) {
REAL.writeLong(output, Float.floatToRawIntBits(((Number) value).floatValue()));
}
else {
throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format("Expected a numeric value for field %s of type REAL: %s [%s]", path, value, value.getClass().getSimpleName()));
}
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Reindex documents so the field holds unquoted JSON numbers: "price": 19.99.
- Map the Presto column as VARCHAR and CAST in queries, or use try_cast to tolerate bad rows.
- Correct the Elasticsearch dynamic/strict mapping so numeric inputs are not coerced into text fields.
Example fix
// before
{"price": "19.99"}
// after
{"price": 19.99} Defensive patterns
Strategy: validation
Validate before calling
SELECT t.price FROM idx t WHERE t.price IS NOT NULL AND TYPEOF(t.price) NOT IN ('real','double','integer') LIMIT 1; Type guard
function isNumericValue(v) { return typeof v === 'number' && Number.isFinite(v); } Try / catch
try { SELECT price FROM "idx" } catch (PrestoException e) { if (e.getErrorCode().getName().equals("ELASTICSEARCH_TYPE_MISMATCH")) { /* switch column to VARCHAR or fix data */ } throw e; } Prevention
- Never quote numbers when generating JSON in pipelines.
- Set an explicit float mapping in Elasticsearch before writing.
- Validate document schema with a JSON Schema check on ingest.
When it happens
Trigger: decode() sees e.g. {"price": "19.99"} or {"price": true} for a field the Presto table declares as REAL.
Common situations: JSON numbers quoted during export/import; Elasticsearch mapping is float but some documents store the value as text (multi-type index); a CSV-to-JSON pipeline left everything as strings.
Related errors
- ELASTICSEARCH_TYPE_MISMATCH
- ELASTICSEARCH_TYPE_MISMATCH
- ELASTICSEARCH_TYPE_MISMATCH
- ELASTICSEARCH_TYPE_MISMATCH
- Invalid array block:
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/6db179e296f235e1.
Report an issue: GitHub.