{"record":{"id":"fb37abed44010a58","repo":"elastic/elasticsearch","slug":"illegal-character-inside-unquoted-field-at","errorCode":null,"errorMessage":"Illegal character inside unquoted field at {}","messagePattern":"Illegal character inside unquoted field at (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java","lineNumber":117,"sourceCode":"            } else if (isWhitespace(c)) {\n                if (trim) {\n                    startIndex++;\n                }\n            } else {\n                state = State.UNQUOTED;\n                builder.setLength(0);\n                return false;\n            }\n        }\n        return true;\n    }\n\n    private boolean processUnquoted() {\n        int spaceCount = 0;\n        for (; currentIndex < length; currentIndex++) {\n            char c = currentChar();\n            if (c == LF || c == CR || c == quote) {\n                throw new IllegalArgumentException(\"Illegal character inside unquoted field at \" + currentIndex);\n            } else if (c == separator) {\n                state = State.START;\n                if (setField(currentIndex - spaceCount)) {\n                    return true;\n                }\n                startIndex = currentIndex + 1;\n                return false;\n            } else if (trim && isWhitespace(c)) {\n                spaceCount++;\n            } else {\n                spaceCount = 0;\n            }\n        }\n        return false;\n    }\n\n    private void processQuoted() {\n        for (; currentIndex < length; currentIndex++) {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java#L99-L135","documentation":"Thrown by CsvParser.processUnquoted when it encounters a line feed, carriage return, or the configured quote character inside a field that was not opened with a quote. Per RFC 4180, quotes are only valid at the start of a field; a bare quote mid-field, or an embedded newline in an unquoted field, is illegal. The parser reports the offending character position.","triggerScenarios":"An unquoted CSV field contains a literal quote character (e.g. value=ab\"cd), or the line was split mid-record so a newline appears inside what should be a quoted field. Triggered for each offending character at the printed index.","commonSituations":"Producers that don't quote fields containing quote characters; multiline records split by a filebeat/multiline codec; CSV export tools that escape quotes by backslash instead of doubling them; field values with embedded CR/LF (Windows line endings) not wrapped in quotes.","solutions":["Configure the upstream producer to quote any field containing the quote char, newline, or separator.","Set up a multiline codec so quoted fields spanning newlines are reassembled before the csv processor.","Pre-process the field with a gsub processor to escape or strip stray quote characters if the producer cannot be changed.","Quarantine via on_failure for manual review."],"exampleFix":"// before - producer emits: abc\"def,123  (bare quote in unquoted field)\n{\"csv\": {\"field\": \"message\", \"target_fields\": [\"name\",\"id\"]}}\n// after - strip stray quotes then parse\n{\"gsub\": {\"field\": \"message\", \"pattern\": \"(?m)(?<=^|,)\\\"(?![^\"]*,(?![^\"]*\\\"))\", \"replacement\": \"'\"}},\n{\"csv\": {\"field\": \"message\", \"target_fields\": [\"name\",\"id\"]}}","handlingStrategy":"validation","validationCode":"// Pre-check that no unquoted field contains a quote or newline before the csv processor:\n{\"script\": {\"source\": \"if (ctx.message =~ /(^|,)[^\\\"]*[^\\\",][\\\"\\r\\n]/) { throw new Exception('illegal char in unquoted field'); }\"}}","typeGuard":null,"tryCatchPattern":"{\"on_failure\": [{\"index\": {\"index\": \"csv-dlq\"}}]}","preventionTips":["Configure the producer to quote fields containing quote, separator, or newline characters.","Reassemble multiline records before parsing.","Strip stray quotes with gsub if the producer cannot be changed."],"tags":["ingest","csv-processor","csv-parsing","data-quality"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}