Skip to content

Instantly share code, notes, and snippets.

@kpietralik
Created January 13, 2018 16:26
Show Gist options
  • Save kpietralik/08599f5557cad9d1825bf28623e62d80 to your computer and use it in GitHub Desktop.
Save kpietralik/08599f5557cad9d1825bf28623e62d80 to your computer and use it in GitHub Desktop.
Logstash configuration file for ingesting Stack Exchange events data from Kafka topic to Elasticsearch index
input {
kafka {
bootstrap_servers => "KAFKA_ADDRESS_AND_PORT"
group_id => "logstash"
topics => ["posts"]
codec => "json"
type => "posts"
consumer_threads => 2
}
}
filter {
mutate {
add_field => { "EventDate" => "%{@timestamp}" }
}
}
output {
if [type] == "posts" {
if [answer_id] {
elasticsearch {
hosts => ["ES_ADDRESS_AND_PORT"]
manage_template => false
index => "posts"
document_type => "answer"
document_id => "%{answer_id}"
}
} else if [comment_id] {
elasticsearch {
hosts => ["ES_ADDRESS_AND_PORT"]
manage_template => false
index => "posts"
document_type => "comment"
document_id => "%{comment_id}"
}
} else if [question_id] {
elasticsearch {
hosts => ["ES_ADDRESS_AND_PORT"]
manage_template => false
index => "posts"
document_type => "question"
document_id => "%{question_id}"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment