{"record":{"id":"419e897ac523eb41","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-419e89","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected a string value for field '%s' of type IP: %s [%s]","messagePattern":"Expected a string value for field '(.+?)' of type IP: (.+?) \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/IpAddressDecoder.java","lineNumber":59,"sourceCode":"    {\n        this.path = requireNonNull(path, \"path is null\");\n        this.ipAddressType = requireNonNull(type, \"type 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 String) {\n            String address = (String) value;\n            Slice slice = castToIpAddress(Slices.utf8Slice(address));\n            ipAddressType.writeSlice(output, slice);\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected a string value for field '%s' of type IP: %s [%s]\", path, value, value.getClass().getSimpleName()));\n        }\n    }\n\n    // This is a copy of IpAddressOperators.castFromVarcharToIpAddress method\n    private Slice castToIpAddress(Slice slice)\n    {\n        byte[] address;\n        try {\n            address = InetAddresses.forString(slice.toStringUtf8()).getAddress();\n        }\n        catch (IllegalArgumentException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, \"Cannot cast value to IPADDRESS: \" + slice.toStringUtf8());\n        }\n\n        byte[] bytes;\n        if (address.length == 4) {\n            bytes = new byte[16];\n            bytes[10] = (byte) 0xff;","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/IpAddressDecoder.java#L41-L77","documentation":"IpAddressDecoder expects the mapped IP field in the Elasticsearch document to be a JSON string; any other type (number, boolean, object, array) triggers this ELASTICSEARCH_TYPE_MISMATCH. The connector casts the string to Presto IPADDRESS only when the raw value is a String.","triggerScenarios":"decode() receives a non-String value for a field mapped as Presto IPADDRESS, e.g. {\"client_ip\": 3232235777} (numeric form) or an object/array value.","commonSituations":"Documents store IPs as integers or packed binary instead of dotted-quad strings; mapping changed over time so old documents hold numeric IPs; a pipeline wrote the IP inside an object.","solutions":["Store the IP as a string (\"192.168.1.1\") in the documents, or reindex converting numeric IPs to strings.","Change the Presto column mapping to BIGINT/JSON to match the stored representation and convert in SQL (e.g. with a UDF/cast).","Fix the ingest pipeline to serialize IPs with InetAddress.getHostAddress()."],"exampleFix":"// before\n{\"client_ip\": 3232235777}\n// after\n{\"client_ip\": \"192.168.1.1\"}","handlingStrategy":"validation","validationCode":"SELECT t.client_ip FROM idx t WHERE t.client_ip IS NOT NULL AND TYPEOF(t.client_ip) <> 'varchar' LIMIT 1;","typeGuard":"function isIpString(v) { return typeof v === 'string' && /^(\\d{1,3}\\.){3}\\d{1,3}$|^([0-9a-fA-F:]+)$/.test(v); }","tryCatchPattern":"try { SELECT client_ip FROM \"idx\" } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_TYPE_MISMATCH\")) { /* map column as VARCHAR and cast in SQL */ } throw e; }","preventionTips":["Always store IPs as dotted-quad/IPv6 strings via getHostAddress().","Map the field as ip in Elasticsearch so values are validated at write time.","Reject non-string IPs during ingest validation."],"tags":["elasticsearch","presto","type-mismatch","ipaddress"],"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"}