Add fields to Logstash Twitter input and Elasticsearch output

丶灬走出姿态 提交于 2020-01-03 04:47:32

问题


I am using logstash to save the twitter stream to elasticsearch. Before saving, I want to

  1. Add a new field which indicates whether the tweet is a RT or reply or organic
  2. Use the tweet id as elasticsearch's document id

But I've been unable to do either! Logstash config file:

input {
twitter {
    oauth_token => ""
    oauth_token_secret => ""
    consumer_key => ""
    consumer_secret => ""
    full_tweet => true
    keywords => ["test"]
}
}

filter {
ruby {
    code => "
        if !event['retweeted_status'].nil?
            event['tweet_type'] = 'Retweet'
        elsif !event['in_reply_to_screen_name'].nil?
            event['tweet_type'] = 'Reply'
        else
            event['tweet_type'] = 'Organic'
        end
    "
}
}

output {
elasticsearch {
    document_id => [id]
    index_type => "twitter"
    protocol => "http"
    bind_host => "127.0.0.1"
}
}

What am I doing wrong?


回答1:


You don't need to drop to ruby to test fields. Try:

if [retweeted_status] {
    mutate {
       add_field => { "tweet_type", "Retweet" }
    }
}

(NOTE: that's pseudo-code; I may have the the {s and => wrong).

As for using the document id, try:

document_id => "%{id}"
|improve this answer

来源:https://stackoverflow.com/questions/28916814/add-fields-to-logstash-twitter-input-and-elasticsearch-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!