Add fields to Logstash Twitter input and Elasticse

2019-06-13 22:28发布

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条回答
小情绪 Triste *
2楼-- · 2019-06-13 23:29

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}"
  • Nope. Neither works. The correct syntax would be add_field => { "tweet_type" => "Retweet" } but doesn't work. The document_id literally becomes "%{id}" – huhahihi Mar 7 '15 at 22:58
    查看更多
登录 后发表回答