Exclude keyword operation in twitter


How to perform exclude keyword operation in twitter.

Exclusion of Twitter keywords

This is documented in the Search API section. Use the minus (-) operator:

beer -root | containing “beer” but not “root”.


Exclusion operation(-) is working for this example beer -root
but i checked different keywords like narendramodi -BJP but in this case we are getting BJP tweets also
can you explain how to track exclusion operation on keywords?


I cannot reproduce that result - I do see that the characters “BJP” appear in the results but not in the Tweet text on their own, only as part of user bios or screen names. In that case, you’d have to filter out those results yourself, the API cannot help you.


Hi ,I Apply the filters and changed the pattern like this “narendramodi%20-BJP%20-%40BJP” but I got @bjp keywords tweets in tweet_text also in my result.
can you help me ?
Thank you


Also unable to reproduce. I see the string as part of other strings in account bios (description) and screen_names. You’ll have to do any further filtering yourself in your own code to clean up the results to what you’re looking for.


Hi ,

I applied the filters and changed the pattern like this " narendramodi%20-%40BJP[0-9A-Za-z]" but i got @BJP tweets in tweet_text .
can you help me ?
how to exclude @BJP4India ,@vasundhar_BJP tweets in tweet_text


Perform the search.

Note that the API does not support regular expressions.

Remove those results from your result set by ignoring them in your code.

(you can also explicitly add -%40[handle you don’t want] for each handle you want to exclude, there may be a lot of them)


okay Thank you
How do you search tweets, excluding the ones which have mentions?
My pattern is
but we are getting tweets like this @BJP4india,@vasundhar_BJP
How to exclude this in pattern ?


You’ll have to manually add each handle you want to exclude to the pattern.


Hi ,
How to perform both inclusion and exclusion operations on 2 or more keywords in twitter search api?

My pattern is like this sachin%20india%20cricket%20-dhoni%20-viratkohli
but we are getting tweets like virat
can you help me?


Unable to reproduce this. I only see the string “virat” inside the expanded_url properties of some of the returned Tweets. Additionally, “virat” is a different string to “viratkohli”, so adding %20-virat to the end of the query successfully excludes those entries as well.

If you’re not seeing the results you expect then please carefully check the documentation on search syntax, where these rules are made clear.


Thank you for your reply