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:
"X data", the rule works properly:
Boolean operators and grouping
String together multiple operators using these tools:| Operator | Description | Example |
|---|---|---|
| AND (space) | Posts must match both conditions | snow day #NoSchool matches Posts with “snow” AND “day” AND #NoSchool |
| OR | Posts must match either condition | grumpy OR cat OR #meme matches Posts with “grumpy” OR “cat” OR #meme |
| NOT (dash) | Exclude Posts matching this condition | cat #meme -grumpy matches Posts with “cat” and #meme but NOT “grumpy” |
| Grouping (parentheses) | Group operators together | (grumpy cat) OR (#meme has:images) matches either group |
A note on negations
- All operators can be negated except for
sample: - The operator
-is:nullcastmust always be negated - Negated operators cannot be used alone
- Do not negate grouped operators. Instead of
skiing -(snow OR day OR noschool), useskiing -snow -day -noschool
Order of operations
When combining AND and OR:- Operators connected by AND logic are combined first
- Then, operators connected with OR logic are applied
| Query | Evaluated as |
|---|---|
apple OR iphone ipad | apple OR (iphone ipad) |
ipad iphone OR android | (iphone ipad) OR android |
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
Tips for building effective rules:- Start specific, then broaden — Create targeted rules that return relevant results
- Use multiple operators — Combine operators to narrow results
- Watch your character count — The entire rule string counts toward the limit
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:Step 3: Broaden for better coverage
We want to capture more sentiment. Add related keywords:Step 4: Adjust for trends
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 anadd JSON body with the value (the rule) and optional tag (to identify matching Posts):
Removing rules
Submit adelete 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:Using Post annotations
Find Japanese Posts about pets (not cats) with images using thecontext: operator:
First, use Post lookup with tweet.fields=context_annotations to identify domain.entity IDs:
- Cats:
domain66,entity852262932607926273 - Pets:
domain65,entity852262932607926273