{"record":{"id":"f796c881d45dbb8b","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-f796c8","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Value out of range for field '%s' of type SMALLINT: %s","messagePattern":"Value out of range for field '(.+?)' of type SMALLINT: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/SmallintDecoder.java","lineNumber":48,"sourceCode":"    private final String path;\n\n    public SmallintDecoder(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            long decoded = ((Number) value).longValue();\n\n            if (decoded < Short.MIN_VALUE || decoded > Short.MAX_VALUE) {\n                throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Value out of range for field '%s' of type SMALLINT: %s\", path, decoded));\n            }\n\n            SMALLINT.writeLong(output, decoded);\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected a numeric value for field '%s' of type SMALLINT: %s [%s]\", path, value, value.getClass().getSimpleName()));\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":58,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/SmallintDecoder.java#L30-L58","documentation":"SmallintDecoder reads the number's long value and rejects it when it does not fit in Presto SMALLINT's 16-bit range (Short.MIN_VALUE..Short.MAX_VALUE), throwing ELASTICSEARCH_TYPE_MISMATCH. The stored JSON type is correct (numeric); only the magnitude is out of range.","triggerScenarios":"decode() finds a numeric value like 40000 or -40000 for a field the Presto table maps to SMALLINT, e.g. {\"count\": 100000}.","commonSituations":"Column declared SMALLINT but documents exceed 32767 (counters, IDs, timestamps in ms); documents grew over time beyond the original value range assumption.","solutions":["Re-map the Presto column to INTEGER or BIGINT so the range accommodates the data.","Clamp or cap the values at ingest time, or reindex with values converted to fit SMALLINT.","If the oversized values are data errors, clean them (e.g. set null) in the source index."],"exampleFix":"// table definition before\ncount SMALLINT\n// after\ncount INTEGER","handlingStrategy":"validation","validationCode":"SELECT MAX(t.count), MIN(t.count) FROM idx t; -- verify fits in [-32768, 32767] before declaring SMALLINT","typeGuard":"function fitsSmallint(n) { return typeof n === 'number' && Number.isInteger(n) && n >= -32768 && n <= 32767; }","tryCatchPattern":"try { SELECT count FROM \"idx\" } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_TYPE_MISMATCH\")) { /* re-map to INTEGER */ } throw e; }","preventionTips":["Profile min/max of the field before choosing SMALLINT.","Prefer INTEGER/BIGINT unless the range is guaranteed.","Clamp or validate values at ingest time."],"tags":["elasticsearch","presto","range-overflow","smallint"],"backgroundTag":"numeric-range-overflow","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"}