Class CsvFormatReader

java.lang.Object
org.elasticsearch.xpack.esql.datasource.csv.CsvFormatReader
All Implemented Interfaces:
Closeable, AutoCloseable, FormatReader, SegmentableFormatReader

public class CsvFormatReader extends Object implements SegmentableFormatReader
CSV/TSV format reader for external datasources.

File format

  • First non-comment line: schema — column:type pairs separated by the delimiter
  • Subsequent lines: data rows
  • Empty/missing values → null
  • Lines starting with the comment prefix (default //) are skipped

Supported types

integer (int, i), long (l), double (d), keyword (k, string, s), text (txt), boolean (bool), datetime (date, dt), ip, null (n).

Configurable options

All options are set via the WITH clause and parsed by withConfig(java.util.Map).
CSV options
ES/ESQL keyDefaultDescription
delimiter,Field separator character
quote"Quoting character
escape\Escape character inside quoted fields
comment//Line comment prefix
null_value(empty)String representation of null
encodingUTF-8Character encoding
datetime_formatISO-8601 / epochCustom datetime pattern
max_field_size10 MBOOM protection; max bytes per field
multi_value_syntaxbracketsMulti-value field syntax
schema_sample_size20,000Number of rows to sample for type inference

Bracket multi-value syntax

When multi_value_syntax is brackets, array-like values support:
  • [a,b,c] — unquoted elements
  • ["a","b","c"] — quoted elements (quotes stripped)
  • [a,"b,c"] — mixed; commas inside quotes are literal

With comma delimiter, a cell like [hello,world] is treated as one column: commas inside [...] are not column delimiters.

Error handling

Controlled by ErrorPolicy and its ErrorPolicy.Mode:
Error modes
ES/ESQL keyBehaviour
fail_fastAbort on first error (default)
skip_rowDrop the entire bad row
null_fieldNull-fill unparseable fields, keep the row

Examples

  EXTERNAL "s3://bucket/data.tsv" WITH {"delimiter": "\t", "error_mode": "skip_row", "max_errors": 100}
  EXTERNAL "s3://bucket/employees.csv" WITH {"multi_value_syntax": "brackets"}
  EXTERNAL "s3://bucket/data.csv" WITH {"multi_value_syntax": "brackets", "error_mode": "skip_row"}

Works with any StorageProvider (HTTP, S3, local filesystem).