{"record":{"id":"8de632a9d5110e08","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected list of elements for field '%s' of type ARRAY: %s [%s]","messagePattern":"Expected list of elements for field '(.+?)' of type ARRAY: (.+?) \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/ArrayDecoder.java","lineNumber":53,"sourceCode":"        this.path = requireNonNull(path, \"path is null\");\n        this.elementDecoder = elementDecoder;\n    }\n\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 List) {\n            BlockBuilder array = output.beginBlockEntry();\n            ((List) data).forEach(element -> elementDecoder.decode(hit, () -> element, array));\n            output.closeEntry();\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected list of elements for field '%s' of type ARRAY: %s [%s]\", path, data, data.getClass().getSimpleName()));\n        }\n    }\n}\n","sourceCodeStart":35,"sourceCodeEnd":57,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/ArrayDecoder.java#L35-L57","documentation":"ArrayDecoder decodes a document field declared as ARRAY. If the raw JSON value for the field is present but is not a List (e.g. a single scalar object or a string), it throws PrestoException(ELASTICSEARCH_TYPE_MISMATCH). Elasticsearch does not have a true array type — a field can hold a single value in some documents and an array in others — so this fires when a document stores a non-list value for a field mapped as an array.","triggerScenarios":"Index contains documents where the ARRAY-typed field holds a single JSON object/string instead of an array; thrown during decode while reading rows in ScanQueryPageSource.","commonSituations":"Schema declared as ARRAY<...> but documents written with a scalar value for that field; dynamic mapping inferred differently per document; data ingestion pipeline changed shape mid-stream.","solutions":["Fix the offending documents to store arrays for the field, or wrap the scalar in an array during ingestion.","Change the Presto column type to match the actual data (e.g. VARCHAR/ROW instead of ARRAY).","Set the connector's text-field/mapping config or use elasticsearch.index mappings to make the field consistently an array.","Use a fallback/COALESCE view if you cannot clean the data (requires connector-level handling)."],"exampleFix":"// before (document)\n{ \"tags\": \"red\" }\n// after\n{ \"tags\": [\"red\"] }","handlingStrategy":"validation","validationCode":"// ensure every document stores an array for the field\ncurl -s 'localhost:9200/<index>/_search?q=tags:*&_source=tags&size=100' \\\n  | jq '[.hits.hits[]._source.tags | select(type != \"array\")]'\n# empty result means all values are arrays","typeGuard":null,"tryCatchPattern":"try {\n    rs = stmt.executeQuery(\"SELECT tags FROM es.default.idx\");\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_TYPE_MISMATCH\")) {\n        log.warn(\"Non-array value in array field; reindex offending documents\");\n    } else { throw e; }\n}","preventionTips":["Enforce array shape in the ingestion pipeline before bulk indexing.","Define explicit ES mappings instead of relying on dynamic mapping.","Sample-scan documents for field shape after pipeline changes."],"tags":["elasticsearch","type-mismatch","decoder","array","data-quality"],"backgroundTag":"type-mismatch-decoding","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"}