{"record":{"id":"6db179e296f235e1","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-6db179","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected a numeric value for field %s of type REAL: %s [%s]","messagePattern":"Expected a numeric value for field (.+?) of type REAL: (.+?) \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/RealDecoder.java","lineNumber":48,"sourceCode":"    private final String path;\n\n    public RealDecoder(String path)\n    {\n        this.path = requireNonNull(path, \"path is null\");\n    }\n\n    @Override\n    public void decode(Hit hit, Supplier<Object> getter, BlockBuilder output)\n    {\n        Object value = getter.get();\n        if (value == null) {\n            output.appendNull();\n        }\n        else if (value instanceof Number) {\n            REAL.writeLong(output, Float.floatToRawIntBits(((Number) value).floatValue()));\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected a numeric value for field %s of type REAL: %s [%s]\", path, value, value.getClass().getSimpleName()));\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":52,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/RealDecoder.java#L30-L52","documentation":"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.","triggerScenarios":"decode() sees e.g. {\"price\": \"19.99\"} or {\"price\": true} for a field the Presto table declares as REAL.","commonSituations":"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.","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."],"exampleFix":"// before\n{\"price\": \"19.99\"}\n// after\n{\"price\": 19.99}","handlingStrategy":"validation","validationCode":"SELECT t.price FROM idx t WHERE t.price IS NOT NULL AND TYPEOF(t.price) NOT IN ('real','double','integer') LIMIT 1;","typeGuard":"function isNumericValue(v) { return typeof v === 'number' && Number.isFinite(v); }","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["elasticsearch","presto","type-mismatch","real"],"backgroundTag":"type-mismatch-decoder","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}