Skip to main content
The filtered stream endpoints deliver Posts that match a set of rules applied to the stream. Rules are made up of operators that match on a variety of Post attributes. Multiple rules can be applied using the POST /tweets/search/stream/rules endpoint. Once you’ve added rules and connected using GET /tweets/search/stream, only Posts matching your rules will be delivered. You do not need to disconnect to add or remove rules.

Rule limitations

Limits on the number of rules depend on your access level. See the filtered stream introduction for specific limits.

Operator types: standalone and conjunction-required

Standalone operators can be used alone or together with any other operators (including those that require conjunction). For example, this rule works because #hashtag is a standalone operator:
Conjunction-required operators cannot be used by themselves in a rule; they can only be used when at least one standalone operator is included. This is because using these operators alone would match an extremely high volume of Posts. For example, the following rules are not supported since they contain only conjunction-required operators:
If we add a standalone operator, such as the phrase "X data", the rule works properly:

Boolean operators and grouping

String together multiple operators using these tools:
A note on negations
  • All operators can be negated except for sample:
  • The operator -is:nullcast must always be negated
  • Negated operators cannot be used alone
  • Do not negate grouped operators. Instead of skiing -(snow OR day OR noschool), use skiing -snow -day -noschool

Order of operations

When combining AND and OR:
  1. Operators connected by AND logic are combined first
  2. Then, operators connected with OR logic are applied
Examples: To eliminate uncertainty, use parentheses:

Punctuation, diacritics, and case sensitivity

Diacritics: Filtered stream rules with accents only match Posts that also include the accent. For example, diacrítica matches diacrítica but not diacritica. Case sensitivity: All operators are case-insensitive. The rule cat matches cat, CAT, and Cat.
Search Posts behaves differentlyWhen building search queries, keywords with accents match Posts both with and without the accents. For example, Diacrítica matches both Diacrítica and Diacritica.

Quote Tweet matching

When using filtered stream, operators match on both the Quote Tweet’s content and the content from the original Post that was quoted.
Search Posts behaves differently—it only matches on the Quote Tweet’s content, not the original Post.

Specificity and efficiency

Using broad operators like a single keyword or hashtag is not recommended—it will match a massive volume of Posts and quickly consume your connection.
Tips for building effective rules:
  1. Start specific, then broaden — Create targeted rules that return relevant results
  2. Use multiple operators — Combine operators to narrow results
  3. Watch your character count — The entire rule string counts toward the limit
Example progression:

Iteratively building a rule

Step 1: Start with a basic rule

Step 2: Test and narrow based on results

We noticed Posts in many languages. Add a language filter:
We’re getting birthday wishes. Exclude them and Retweets:

Step 3: Broaden for better coverage

We want to capture more sentiment. Add related keywords:
Holiday Posts are appearing. Exclude them:

Adding and removing rules

Use POST /2/tweets/search/stream/rules to add or remove rules.

Adding rules

Submit an add JSON body with the value (the rule) and optional tag (to identify matching Posts):

Removing rules

Submit a delete JSON body with the rule IDs to remove:

Rule examples

Tracking a natural disaster

Match Posts from weather agencies about Hurricane Harvey:

Sentiment analysis for #nowplaying

Positive sentiment:
Negative sentiment:

Using Post annotations

Find Japanese Posts about pets (not cats) with images using the context: operator: First, use Post lookup with tweet.fields=context_annotations to identify domain.entity IDs:
  • Cats: domain 66, entity 852262932607926273
  • Pets: domain 65, entity 852262932607926273

Next steps

Operators reference

Complete list of available operators

Filtered stream quickstart

Connect to your stream

Sample code

Code examples in multiple languages