Logging Kafka topics and writing to Elastic Search using Logstash

tech kamar
Sep 30, 2024

To install and setup ElasticSearch in local. Click Here

Download LogStash

wget https://artifacts.elastic.co/downloads/logstash/logstash-8.15.2-linux-x86_64.tar.gz

tar -xvf logstash-8.15.2-linux-x86_64.tar.gz

Configure and run it

Create a file called logstash.conf

input { 
kafka {
topics => ["test_microservice"]
decorate_events => 'basic'
}
}
filter {
json {
source => "message"
}
mutate {
add_field => {
"kafka-topic" => "%{[@metadata][kafka][topic]}"
}
}
}
output {
stdout{}
elasticsearch {
hosts => "http://127.0.0.1:9200"
user => 'elastic'
password => 'HkieavcIJjSa9EZanrtr'
index => 'es_index'
}
}

In the above conf,

Logstash reads messages from kafka topic test_microservice and writes into elasticsearch.

Run Logstash

bin/logstash -f logstash.conf

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response