Building a query
Query limitations! Your queries will be limited depending on which access level you are using. Your query can be 512 characters long for pay-per-use customers, or up to 4,096 characters for Enterprise customers. If you have Enterprise access, please reach out to your account manager. Operator availability While most operators are available to any developer, there are several that are reserved for those that have been approved for Enterprise access. We list which access level each operator is available to in the list of operators table using the following labels:- Core operators: Available when using any Project.
- Advanced operators: Available when using a Project with Enterprise access
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, the following query will work because it uses the #hashtag operator, which is standalone: #xapiv2 Conjunction-required operators cannot be used by themselves in a query; they can only be used when at least one standalone operator is included in the query. This is because using these operators alone would be far too general, and would match on an extremely high volume of Posts. For example, the following queries are not supported since they contain only conjunction-required operators: has:media has:links OR is:retweet If we add in a standalone operator, such as the phrase “X data”, the query would then work properly. “X data” has:mentions (has:media OR has:links)Boolean operators and grouping
If you would like to string together multiple operators in a single query, you have the following tools at your disposal:| AND logic | Successive operators with a space between them will result in boolean “AND” logic, meaning that Posts will match only if both conditions are met. For example, snow day #NoSchool will match Posts containing the terms snow and day and the hashtag #NoSchool. |
| OR logic | Successive operators with OR between them will result in OR logic, meaning that Posts will match if either condition is met. For example, specifying grumpy OR cat OR #meme will match any Posts containing at least the terms grumpy or cat, or the hashtag #meme. |
| NOT logic, negation | Prepend a dash (-) to a keyword (or any operator) to negate it (NOT). For example, cat #meme -grumpy will match Posts containing the hashtag #meme and the term cat, but only if they do not contain the term grumpy. One common query clause is -is:retweet, which will not match on Retweets, thus matching only on original Posts, Quote Tweets, and replies. All operators can be negated, but negated operators cannot be used alone. |
| Grouping | You can use parentheses to group operators together. For example, (grumpy cat) OR (#meme has:images) will return either Posts containing the terms grumpy and cat, or Posts with images containing the hashtag #meme. Note that ANDs are applied first, then ORs are applied. |
- Operators connected by AND logic are combined first
- Then, operators connected with OR logic are applied
- apple OR iphone ipad would be evaluated as apple OR (iphone ipad)
- ipad iphone OR android would be evaluated as (iphone ipad) OR android
- (apple OR iphone) ipad
- iphone (ipad OR android)
- Using broad, standalone operators for your query such as a single keyword or #hashtag is generally not recommended since it will likely match on a massive volume of Posts. Creating a more robust query will result in a more specific set of matching Posts, and will hopefully increase the accuracy of your Post counts to help you find more valuable insights.
- For example, if your query was just the keyword happy you will likely get anywhere from 200,000 - 300,000 Posts per day.
- Adding more conditional operators narrows your results, for example (happy OR happiness) place_country:GB -birthday -is:retweet
- Writing efficient queries is also beneficial for staying within the characters query length restriction. The character count includes the entire query string including spaces and operators.
- For example, the following query is 59 characters long: (happy OR happiness) place_country:GB -birthday -is:retweet