Filterquery with streaming API



I am using the Twitter Streaming API with Apache Storm to get the tweets and want to filter the tweets for specific keywords. I had a look at some examples i found on the internet and using the same code to filter for the keywords.

I get lots of tweets, unfortunately, the filter doesn’t seem to work at all. Here is the code i am using:

TwitterStreamFactory fact = new TwitterStreamFactory(;

twitterStream = fact.getInstance();

FilterQuery tweetFilterQuery = new FilterQuery();
tweetFilterQuery.track(new String[]{"bitcoin"});

twitterStream.addListener(new TweetListener());


The resulting tweets are then displayed on the console.

I don’t see, why this code does not work. Any hints?



No need to call twitterStream.sample() at the end - what ends up happening is you open a filter stream connection with twitterStream.filter() then immediately close it and open up a sample stream.

Rather than using just Twitter4J, is a good library to use for the streaming API - it implements Twitter4J interfaces so you won’t have to change much if you’re using Twitter4J Status objects.

The setup that worked well for me was HBC dumping json into a Kafka queue that Storm can consume.


Commenting out the sample worked. Thanks for your help!