{"record":{"id":"38a9179c76bbfcc8","repo":"prestodb/presto","slug":"elasticsearch-type-mismatch-38a917","errorCode":"ELASTICSEARCH_TYPE_MISMATCH","errorMessage":"Expected a boolean value for field %s of type BOOLEAN: %s [%s]","messagePattern":"Expected a boolean value for field (.+?) of type BOOLEAN: (.+?) \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/BooleanDecoder.java","lineNumber":48,"sourceCode":"    private final String path;\n\n    public BooleanDecoder(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 Boolean) {\n            BOOLEAN.writeBoolean(output, (Boolean) value);\n        }\n        else {\n            throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format(\"Expected a boolean value for field %s of type BOOLEAN: %s [%s]\", path, value, value.getClass().getSimpleName()));\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":52,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/BooleanDecoder.java#L30-L52","documentation":"BooleanDecoder decodes a field declared as BOOLEAN. Null decodes to NULL and a genuine Boolean is written directly; any other value (string like \"true\"/\"false\", number) throws PrestoException(ELASTICSEARCH_TYPE_MISMATCH) because the value cannot be interpreted as a boolean.","triggerScenarios":"A document stores a non-boolean value (e.g. \"active\": \"true\" as a string, or \"active\": 1) in a field declared BOOLEAN in the Presto schema; thrown during row decoding.","commonSituations":"Documents ingested from CSV/JSON pipelines that serialize booleans as strings; dynamic mapping inferred boolean in one document, string in another; Presto schema ahead of actual data types.","solutions":["Fix documents to store real JSON booleans (true/false, unquoted).","Change the Presto column to VARCHAR if the underlying data is strings, and cast in queries.","Normalize the ingestion pipeline to emit native booleans.","Reindex with an ingest pipeline converting strings to booleans."],"exampleFix":"// before (document)\n{ \"is_active\": \"true\" }\n// after\n{ \"is_active\": true }","handlingStrategy":"validation","validationCode":"// find documents whose boolean field is a string\ncurl -s 'localhost:9200/<index>/_search' -H 'Content-Type: application/json' -d '{\n  \"query\": { \"script\": { \"script\": {\n    \"source\": \"doc.containsKey(\\\"is_active\\\") && !(doc[\\\"is_active\\\"].value instanceof Boolean)\"\n  } } } }'","typeGuard":null,"tryCatchPattern":"try {\n    rs = stmt.executeQuery(\"SELECT is_active FROM es.default.idx\");\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_TYPE_MISMATCH\")) {\n        // reindex with a script converting \"true\"/\"false\" strings to booleans\n    } else { throw e; }\n}","preventionTips":["Emit native JSON booleans from ingestion code (unquoted true/false).","Add an ES ingest pipeline with a boolean convert processor for CSV sources.","Align the Presto column type (BOOLEAN vs VARCHAR) with the actual mapping."],"tags":["elasticsearch","type-mismatch","decoder","boolean","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"}