elastic/elasticsearch · error · IllegalArgumentException

character '{}' after quoted field at {}

Error message

character '{}' after quoted field at {}

What it means

Thrown by CsvParser when, after a closing quote of a quoted field, it encounters a character that is neither whitespace (space/tab) nor the field separator nor a line terminator. The parser allows trailing whitespace after a closing quote but any other character (a second quote, a letter, etc.) is invalid CSV and is rejected with the offending character and its position.

Source

Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java:169

        boolean shouldSetField = true;
        for (; currentIndex < length; currentIndex++) {
            c = currentChar();
            if (c == separator) {
                if (shouldSetField && setField(currentIndex - 1)) {
                    return true;
                }
                startIndex = currentIndex + 1;
                state = State.START;
                return false;
            } else if (isWhitespace(c)) {
                if (shouldSetField) {
                    if (setField(currentIndex - 1)) {
                        return true;
                    }
                    shouldSetField = false;
                }
            } else {
                throw new IllegalArgumentException("character '" + c + "' after quoted field at " + currentIndex);
            }
        }
        return true;
    }

    private char currentChar() {
        return line.charAt(currentIndex);
    }

    private static boolean isWhitespace(char c) {
        return c == SPACE || c == TAB;
    }

    private boolean setField(int endIndex) {
        String value;
        if (builder.length() == 0) {
            value = line.substring(startIndex, endIndex);
        } else {

View on GitHub (pinned to db6a809a66)

Solutions

  1. Inspect the input at the reported character index and fix the producer's quoting/separator logic.
  2. Use a gsub processor to insert the configured separator where it is missing.
  3. Quarantine the malformed record with an on_failure block for offline repair.

Example fix

// before - input: "price"USD,12.5  (text immediately after closing quote)
{"csv": {"field": "message", "target_fields": ["label","amount"]}}
// after - producer must separate fields correctly: "price",USD,12.5
// (fix at source; or pre-clean with gsub if pattern is predictable)
Defensive patterns

Strategy: validation

Validate before calling

// Validate that closing quotes are followed only by whitespace, separator, or end-of-line:
{"script": {"source": "if (ctx.message =~ /\"[^\"\r\n, \t]/) { throw new Exception('char after quoted field'); }"}}

Try / catch

{"on_failure": [{"index": {"index": "csv-dlq"}}]}

Prevention

When it happens

Trigger: Input like "abc"def,123 or "abc"x where text follows the closing quote of a quoted field. The first character after the closing quote that is not space/tab/separator triggers the error at that index.

Common situations: Concatenated fields where a producer forgot the separator; CSV where quotes were intended as literal characters but placed adjacent to a quoted value; copy-paste concatenation of partial CSV rows; malformed exports that append a unit or currency symbol after a quoted value.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/30f9a875df9fade6. Report an issue: GitHub.