A Logstash pipeline has three stages: an input that reads events, optional filters that parse and enrich them, and one or more outputs that send them somewhere. The gist above shows four small configurations: a file-to-file pipeline, a CSV parsing filter, outputs to Elasticsearch, stdout and CSV, and a conditional output skeleton. This page explains each one, fixes the parts that do not run as written, and builds them into a complete pipeline you can test.
How a Logstash pipeline is structured
Every Logstash configuration file is made of up to three blocks. Each block holds one or more plugins, and each event passes through them in order: input, then filter, then output. The syntax is Logstash's own configuration language. It is not YAML, even though the gist files use a .yaml extension. Save pipeline files as .conf.
| Stage | Purpose | Plugins used above |
|---|---|---|
| input | Reads raw data and creates events | file |
| filter | Parses, transforms or enriches each event | csv |
| output | Sends events to a destination | elasticsearch, stdout, file, csv |
Each event has a message field containing the raw line, plus metadata such as @timestamp, host and log (or path in older versions). Filters add new fields. Outputs can refer to any field with [fieldname] in conditionals or %{fieldname} inside strings.
Understanding the file input settings
pathis the file or glob to read, for example/var/log/app/*.log. It must be an absolute path. On Windows, use forward slashes:C:/logs/app.log.start_position => "beginning"reads existing content of files Logstash has never seen. Without it, Logstash only reads lines appended after startup, which is why test pipelines often seem to do nothing.sincedb_path => "/dev/null"stops Logstash from remembering how far it has read, so the file is processed again on each run. This is useful for testing but wrong for production, where it causes duplicates after every restart. On Windows the equivalent is"NUL".mode => "read"(optional) treats files as complete batches instead of tailing them. That suits one-off loads such asbatch_10day.txt.
Corrected versions of the gist examples
The simple input/output example was written for Logstash 2.3.1 on Windows. ignore_older => 0 dates from that era. In current versions of the file input it is a duration in seconds, and setting it to 0 can cause files to be ignored rather than read. Remove it. The output path also needs a sincedb setting that works on Windows:
# simple.conf
input {
file {
path => "C:/logstash/data/logstash-tutorial-dataset"
start_position => "beginning"
sincedb_path => "NUL"
}
}
output {
stdout { codec => rubydebug }
file {
path => "C:/logstash/output/output.txt"
}
}Code language: PHP (php)
The multi-output example writes the CSV file to path-to-file\syslogs-.... In Logstash strings, a backslash can be read as an escape character, so use forward slashes or a Linux path. The count field is only filled in if a filter creates it. Otherwise that column comes out empty.
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "logstash_index"
}
stdout {
codec => rubydebug
}
csv {
path => "/var/log/logstash-export/syslogs-%{+yyyy.MM.dd}.csv"
fields => ["@timestamp", "message", "count"]
}
}Code language: PHP (php)
Note: The csv_options write_headers/headers pattern in the gist is passed straight to Ruby's CSV library, and in some plugin versions it writes the header row again before every event. Check your output file. If the headers repeat, remove csv_options and add the header line in a separate step. If the csv output plugin is missing, install it with bin/logstash-plugin install logstash-output-csv.
A complete CSV log pipeline into Elasticsearch
The filter example splits semicolon-separated batch job lines into named fields. The version below goes one step further. It joins date and time into a real event timestamp, converts the error code to a number, removes the raw line, and indexes the result. Example input line:
SUCCESS;2022-03-01;10:15:22;WS01;Payroll;JOB_123;0Code language: CSS (css)
# /usr/share/logstash/pipeline/batch.conf
input {
file {
path => "/usr/share/logstash/batch_10day.txt"
start_position => "beginning"
sincedb_path => "/dev/null" # testing only
}
}
filter {
csv {
separator => ";"
columns => ["status", "date", "time", "workstation", "application", "job", "Error_code"]
}
mutate {
add_field => { "job_time" => "%{date} %{time}" }
convert => { "Error_code" => "integer" }
}
date {
match => ["job_time", "yyyy-MM-dd HH:mm:ss"]
target => "@timestamp"
remove_field => ["job_time"]
}
if "_csvparsefailure" not in [tags] {
mutate { remove_field => ["message"] }
}
}
output {
elasticsearch {
hosts => ["https://localhost:9200"]
user => "elastic"
password => "${ES_PWD}"
ssl_certificate_authorities => ["/usr/share/logstash/certs/http_ca.crt"]
index => "batch-jobs-%{+YYYY.MM.dd}"
}
stdout { codec => rubydebug }
}Code language: PHP (php)
datereplaces the ingestion time in@timestampwith the time the job actually ran, so Kibana time filters show the right results.${ES_PWD}reads the password from an environment variable or the Logstash keystore, so it is never stored in plain text in the file.- Elasticsearch 8.x enables TLS and authentication by default, which is why the URL uses
httpsand supplies credentials. Older versions of the elasticsearch output plugin usecacertinstead ofssl_certificate_authorities. - The raw
messageis kept for lines that fail to parse, which makes debugging easier.
Running and testing the pipeline
- Check the syntax without starting the pipeline:
bin/logstash -f batch.conf --config.test_and_exit. A valid file printsConfiguration OK. - Run it in the foreground:
bin/logstash -f batch.conf. Add--config.reload.automaticto pick up edits without restarting. - Watch the
rubydebugoutput on the console to confirm the fields are parsed. - Query Elasticsearch:
curl -u elastic --cacert http_ca.crt "https://localhost:9200/batch-jobs-*/_search?size=1&pretty".
{
"@timestamp" => 2022-03-01T10:15:22.000Z,
"status" => "SUCCESS",
"date" => "2022-03-01",
"time" => "10:15:22",
"workstation" => "WS01",
"application" => "Payroll",
"job" => "JOB_123",
"Error_code" => 0,
"@version" => "1"
}Code language: PHP (php)
Your output will also contain fields such as host, log and event, depending on the Logstash version and its ECS compatibility setting. The date filter reads times as UTC unless you set timezone, for example timezone => "Asia/Kolkata".
Routing events with conditional outputs
The conditional output gist is pseudocode. output for this type of message is not valid syntax, and Logstash will refuse to start if it is left in. Replace each placeholder with a real output plugin. Use else if and else so that each event matches exactly one branch:
output {
if "_csvparsefailure" in [tags] {
file { path => "/var/log/logstash/failed-%{+YYYY.MM.dd}.log" }
} else if [status] == "ERROR" {
elasticsearch {
hosts => ["https://localhost:9200"]
user => "elastic"
password => "${ES_PWD}"
ssl_certificate_authorities => ["/usr/share/logstash/certs/http_ca.crt"]
index => "batch-errors-%{+YYYY.MM.dd}"
}
} else {
elasticsearch {
hosts => ["https://localhost:9200"]
user => "elastic"
password => "${ES_PWD}"
ssl_certificate_authorities => ["/usr/share/logstash/certs/http_ca.crt"]
index => "batch-jobs-%{+YYYY.MM.dd}"
}
}
}Code language: PHP (php)
Conditionals support ==, !=, <, >, regex matches with =~, membership with in, and and/or/not. Nested fields use the syntax [log][level]. The same conditionals also work inside the filter block.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Logstash starts but no events appear | The file was already recorded in sincedb, or start_position is missing | Set start_position => "beginning" and delete the sincedb file or point sincedb_path at /dev/null |
Expected one of [ \t\r\n], "#", ... at startup | Syntax error, often leftover placeholder text or a missing brace | Run --config.test_and_exit and check the reported line and column |
Events tagged _csvparsefailure | Wrong separator, or quotes inside fields | Check separator, and set quote_char if needed |
Events tagged _dateparsefailure | The date pattern does not match the data | Compare the match pattern with a real value, including zero padding |
401 Unauthorized or SSL handshake errors | Elasticsearch 8.x security is enabled | Use https, valid credentials and the cluster CA certificate |
| File input reads nothing on Windows | Backslashes in path | Use forward slashes, for example C:/logs/*.log |
| Permission denied on input or output path | The Logstash service user cannot read or write the path | Fix ownership or permissions for the logstash user |
Best practices
- Keep one pipeline per data source, defined in
pipelines.yml, rather than one large file full of conditionals. - Remove
sincedb_path => "/dev/null"and thestdoutoutput before going to production. Both are debugging aids. - Store credentials in the Logstash keystore (
bin/logstash-keystore add ES_PWD) rather than in pipeline files. - Use lowercase index names. Elasticsearch rejects index names that contain uppercase letters.
- Use date-based indices or Elasticsearch data streams with lifecycle policies so old data can be deleted automatically.
- Name fields consistently. A mix such as
Error_codealongside lowercase fields makes Kibana queries harder.
Frequently asked questions
Is a Logstash config file YAML?
No. Pipeline files use Logstash's own configuration syntax and normally have a .conf extension. Only the settings files logstash.yml and pipelines.yml are YAML.
Why does Logstash not read my existing log file?
By default the file input tails files, reading only new lines, and it records read positions in a sincedb file. Set start_position => "beginning" for new files, and clear the sincedb or set sincedb_path to /dev/null when you are testing.
Can one Logstash pipeline send data to multiple outputs?
Yes. Every plugin listed in the output block receives every event, unless you wrap the plugins in conditionals to route events by field values or tags.
Is the filter section required in Logstash?
No. A pipeline needs only an input and an output. Filters are optional and are used when events must be parsed, enriched or cleaned before output.
How do I test a Logstash configuration without running it?
Run bin/logstash -f yourfile.conf --config.test_and_exit. It parses the configuration and reports syntax errors without processing any events.
Related tutorials
- What is ELK Stack and use cases of ELK Stack?
- What is Elasticsearch and use cases of Elasticsearch?
- Top 50 Logstash Interview Questions and Answers
- More Elastic Stack (ELK) tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals