Install & run

Logstash tutorial: build your first pipeline step by step

Five short stages, each building on the last. By the end you have a pipeline that reads a real log file, extracts fields and indexes the result.

Updated 22 November 202611 min readWritten for Logstash 9.5

Three numbered checkpoints from stdin through a pipeline configuration to rubydebug output

Stage 1: a one-line pipeline

Start from your Logstash folder. On Linux and macOS the launcher is bin/logstash; on Windows it is bin\logstash.bat. The -e flag accepts a whole pipeline on the command line:

bin/logstash -e 'input { stdin { } } output { stdout { codec => rubydebug } }' 

When Pipeline started appears, type a few words and press Enter. Each line becomes an event with @timestamp, message and host metadata. This proves Java, plugins and the event flow all work. Stop it with Ctrl+C.

On Linux, Logstash 9.x refuses to run as root by default. Run these commands as your normal user. If you installed the deb or rpm package, the service runs as the logstash user for the same reason.

Stage 2: move the pipeline into a file

Create tutorial.conf in the config folder:

input  { stdin { } }
filter {
  mutate { add_field => { "[labels][stage]" => "two" } }
}
output { stdout { codec => rubydebug } }
bin/logstash -f config/tutorial.conf --config.test_and_exit
bin/logstash -f config/tutorial.conf

Typed lines now gain a labels.stage field. That one mutate filter is the pattern for everything else: filters receive the event, change it and pass it on.

Stage 3: read a sample log file

Save these lines as sample.log somewhere convenient, for example /tmp/sample.log or C:/logs/sample.log:

198.51.100.24 - - [02/Nov/2026:10:01:07 +0000] "GET /index.html HTTP/1.1" 200 3120 "-" "Mozilla/5.0"
198.51.100.24 - - [02/Nov/2026:10:01:08 +0000] "GET /style.css HTTP/1.1" 200 812 "/index.html" "Mozilla/5.0"
203.0.113.9 - - [02/Nov/2026:10:02:44 +0000] "POST /api/login HTTP/1.1" 401 64 "-" "curl/8.5.0"

Replace the input in tutorial.conf with a file input:

input {
  file {
    path => "/tmp/sample.log"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}

On Windows, use path => "C:/logs/sample.log" and sincedb_path => "NUL". The sincedb setting makes Logstash forget its read position each run, which is what you want while experimenting. The file input keeps watching the file, so the pipeline will not exit by itself; stop it when the three events have printed.

Stage 4: parse the lines

Now give the filter section real work. Replace it with:

filter {
  grok {
    match => { "message" => "%{COMBINEDAPACHELOG}" }
  }
  date {
    match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
    remove_field => ["timestamp"]
  }
  if [http][response][status_code] >= 400 {
    mutate { add_tag => ["client_error"] }
  }
}

Run it again. Each event now has structured fields such as [source][address], [http][request][method] and [url][original], and @timestamp is the time from the log line rather than the time Logstash read it. The login attempt carries the client_error tag. If you see _grokparsefailure instead, compare your sample file with the lines above character by character; the grok examples article explains how to debug patterns.

Stage 5: send events to Elasticsearch

Keep the stdout output while you test and add an elasticsearch output next to it. Modern Elasticsearch clusters use TLS and authentication by default:

output {
  elasticsearch {
    hosts    => ["https://localhost:9200"]
    api_key  => "${ES_API_KEY}"
    ssl_certificate_authorities => ["/path/to/http_ca.crt"]
  }
  stdout { codec => rubydebug }
}

Store the API key in the keystore (bin/logstash-keystore add ES_API_KEY) rather than in the file. With default settings and no index option, recent versions write to a data stream named logs-generic-default. In Kibana, create a data view for logs-* and open Discover to see your three parsed events.

Where to go next

  • Replace the file input with the beats input and let Filebeat ship logs from many servers.
  • Split different sources into separate pipelines with pipelines.yml; pipeline configuration explained shows how.
  • Before production, read the safety checklist and decide whether you need a persistent queue.