{"record":{"id":"da2d4cac3baa12d9","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-da2d4c","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected a numeric value for field '%s' of type INTEGER: %s [%s]","messagePattern":"Expected a numeric value for field '(.+?)' of type INTEGER: (.+?) \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/IntegerDecoder.java","lineNumber":49,"sourceCode":"    private final String path;\n\n    public IntegerDecoder(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            INTEGER.writeLong(output, toIntExact(((Number) value).longValue()));\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected a numeric value for field '%s' of type INTEGER: %s [%s]\", path, value, value.getClass().getSimpleName()));\n        }\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":53,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/IntegerDecoder.java#L31-L53","documentation":"The Elasticsearch connector's IntegerDecoder found a document field value that is not a java.lang.Number when decoding it into a Presto INTEGER column. The connector only coerces actual numbers; any other JSON type (string, boolean, object, array) is rejected rather than silently cast. This keeps Presto's type system from receiving garbage data from loosely-typed Elasticsearch documents.","triggerScenarios":"decode() is called with a hit field whose mapped Presto type is INTEGER but whose stored JSON value is a non-number, e.g. {\"age\": \"42\"} or {\"age\": true} while the connector metadata declares the column as INTEGER.","commonSituations":"Elasticsearch dynamic mapping created the field as text/keyword from early string documents, then the Presto external table was declared INTEGER; schema drift between documents in the same index (some documents use strings, others numbers); accidental JSON quoting in the indexing pipeline.","solutions":["Fix the document data so the field holds a JSON number, e.g. reindex with \"age\": 42 instead of \"age\": \"42\".","Change the Presto table column mapping to VARCHAR/JSON to match the actual stored type, and cast in SQL.","Add or fix the Elasticsearch dynamic mapping / Presto field definition so the field is mapped as integer before ingesting."],"exampleFix":"// before (document)\n{\"age\": \"42\"}\n// after\n{\"age\": 42}","handlingStrategy":"validation","validationCode":"SELECT t.age FROM idx t WHERE t.age IS NOT NULL AND TYPEOF(t.age) <> 'integer' LIMIT 1;\n-- or at ingest: assert(typeof doc.age === 'number')","typeGuard":"function isIntegerValue(v) { return typeof v === 'number' && Number.isFinite(v) && Number.isInteger(v); }","tryCatchPattern":"try { SELECT age FROM \"idx\" } catch (PrestoException e) { if (\"ELASTICSEARCH_TYPE_MISMATCH\".equals(e.getErrorCode().getName())) { /* re-map column or clean data */ } else { throw e; } }","preventionTips":["Define an explicit Elasticsearch mapping with integer type before indexing.","Disable dynamic mapping coercion of numbers to text (set dynamic: strict or numeric_detection).","Validate JSON types in the ingest pipeline before bulk indexing.","Declare Presto column types to match the real document types."],"tags":["elasticsearch","presto","type-mismatch","decoder"],"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"}