{"record":{"id":"7706a5f30d0fbfb1","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-7706a5","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected single value for column '%s', found: %s","messagePattern":"Expected single value for column '(.+?)', found: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/TimestampDecoder.java","lineNumber":62,"sourceCode":"    public TimestampDecoder(ConnectorSession session, String path)\n    {\n        this.path = requireNonNull(path, \"path is null\");\n        this.zoneId = session.getSqlFunctionProperties().isLegacyTimestamp() ?\n                ZoneId.of(session.getSqlFunctionProperties().getTimeZoneKey().getId()) :\n                ZoneOffset.UTC;\n    }\n\n    @Override\n    public void decode(Hit hit, Supplier<Object> getter, BlockBuilder output)\n    {\n        Object value = getter.get();\n        Map<String, JsonData> fields = hit.fields();\n        JsonData documentField = fields.get(path);\n\n        if (documentField != null) {\n            int size = documentField.toJson().asJsonArray().size();\n            if (size > 1) {\n                throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected single value for column '%s', found: %s\", path, size));\n            }\n            String valueString = documentField.toJson().asJsonArray().get(0).toString();\n            value = valueString.replace(\"\\\"\", \"\");\n        }\n\n        if (value == null) {\n            output.appendNull();\n            return;\n        }\n\n        LocalDateTime timestamp;\n        if (value instanceof String) {\n            timestamp = ISO_DATE_TIME.parse((String) value, LocalDateTime::from);\n        }\n        else if (value instanceof Number) {\n            timestamp = LocalDateTime.ofInstant(Instant.ofEpochMilli(((Number) value).longValue()), ZULU);\n        }\n        else {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/TimestampDecoder.java#L44-L80","documentation":"TimestampDecoder reads the field via hit.fields() and requires exactly one value; if the JSON array for the column has more than one element it throws ELASTICSEARCH_TYPE_MISMATCH. This happens when a multi-valued (array) timestamp is returned for a column declared as a scalar TIMESTAMP.","triggerScenarios":"decode() finds fields.get(path) yielding a JSON array of size > 1, e.g. {\"event_time\": [\"2024-01-01T00:00:00\", \"2024-06-01T00:00:00\"]} for a TIMESTAMP column, with stored_fields retrieval enabled.","commonSituations":"The Elasticsearch mapping for the field became an array (multiple values indexed over time); Presto column declared scalar TIMESTAMP while the index holds multi-valued timestamps; a pipeline appended instead of replacing values.","solutions":["De-duplicate or pick one value in the documents (reindex with a script or ingest pipeline taking the first element).","Change the Presto column to ARRAY(TIMESTAMP) or ARRAY(VARCHAR) and index into it in queries.","Fix the mapping (set store:false / use docvalue_fields config) or the writer so only one timestamp value is stored per field."],"exampleFix":"// before\n{\"event_time\": [\"2024-01-01T00:00:00\", \"2024-06-01T00:00:00\"]}\n// after\n{\"event_time\": \"2024-01-01T00:00:00\"}","handlingStrategy":"validation","validationCode":"// before querying, ensure only one value per doc\nGET idx/_search {\"_source\": [\"event_time\"], \"script_fields\": {\"n\": {\"script\": \"doc['event_time'].size()\"}}} // any n>1 will fail","typeGuard":"function isSingleTimestamp(v) { return !Array.isArray(v); }","tryCatchPattern":"try { SELECT event_time FROM \"idx\" } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_TYPE_MISMATCH\")) { /* map column as ARRAY or dedupe */ } throw e; }","preventionTips":["Ensure the Elasticsearch mapping never makes the timestamp field multi-valued (one value per document).","Replace (not append) timestamp values in updates/pipelines.","Declare ARRAY(Timestamp) if multiple values are legitimate."],"tags":["elasticsearch","presto","type-mismatch","timestamp","multivalue"],"backgroundTag":"multivalue-field-mismatch","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"}