{"record":{"id":"f25e52d049640ac0","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-f25e52","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected object for field '%s' of type ROW: %s [%s]","messagePattern":"Expected object for field '(.+?)' of type ROW: (.+?) \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/RowDecoder.java","lineNumber":60,"sourceCode":"\n    @Override\n    public void decode(Hit hit, Supplier<Object> getter, BlockBuilder output)\n    {\n        Object data = getter.get();\n\n        if (data == null) {\n            output.appendNull();\n        }\n        else if (data instanceof Map) {\n            BlockBuilder row = output.beginBlockEntry();\n            for (int i = 0; i < decoders.size(); i++) {\n                String field = fieldNames.get(i);\n                decoders.get(i).decode(hit, () -> getField((Map<String, Object>) data, field), row);\n            }\n            output.closeEntry();\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected object for field '%s' of type ROW: %s [%s]\", path, data, data.getClass().getSimpleName()));\n        }\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":64,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/RowDecoder.java#L42-L64","documentation":"RowDecoder expects the document field for a Presto ROW (struct) column to be a JSON object (Map). When the retrieved data is not a Map — e.g. an array or scalar — it throws ELASTICSEARCH_TYPE_MISMATCH, since struct fields can only be built from nested objects.","triggerScenarios":"decode() is invoked for a ROW-typed path where the stored value is an array, string, or number instead of a nested object, e.g. {\"address\": [\"a\",\"b\"]} mapped as ROW(a VARCHAR, b VARCHAR).","commonSituations":"Documents changed shape from object to array of values; nested field flattened by an ingest pipeline; wrong column type declared in the external table definition.","solutions":["Make the documents store a nested object: {\"address\": {\"a\": \"x\", \"b\": \"y\"}} or reindex accordingly.","If the values are arrays, map the column as ARRAY(ROW(...)) or ARRAY(VARCHAR) instead of ROW.","Fix the table's column definition so it matches the actual document structure."],"exampleFix":"// before\n{\"address\": [\"street\", \"city\"]}\n// after\n{\"address\": {\"street\": \"...\", \"city\": \"...\"}}","handlingStrategy":"validation","validationCode":"SELECT t.address FROM idx t WHERE t.address IS NOT NULL AND TYPEOF(t.address) <> 'row' LIMIT 1; // detect shape drift","typeGuard":"function isRowObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }","tryCatchPattern":"try { rows = SELECT address FROM \"idx\"; } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_TYPE_MISMATCH\")) { /* re-declare column as ARRAY or fix docs */ } throw e; }","preventionTips":["Keep document nesting shape stable; use explicit mapping for object fields.","Map array-shaped data as ARRAY(ROW(...)) from the start.","Add an ingest pipeline that rejects or reshapes non-object values for struct fields."],"tags":["elasticsearch","presto","type-mismatch","row","struct"],"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"}