Gmail Search Patterns
Reference for constructing effective Gmail search queries. Complements Gmail API Usage Guide which covers API mechanics.
Search Philosophy
Wide net > narrow miss. It's better to return false positives that inference can filter than to miss real matches with overly restrictive queries.
Search by content patterns, not sender domains. Subject lines follow predictable patterns ("Your flight confirmation", "Order shipped"). Sender addresses vary wildly (hundreds of airlines, booking services change domains, companies rebrand).
Let inference judge relevance. Code should fetch candidates; inference should decide what's actually relevant. Don't try to be clever with heuristics in code.
Operator Reference
| Operator | Usage | Notes |
|---|---|---|
subject:"phrase" |
subject:"flight confirmation" |
Most reliable - searches exact phrase in subject |
"phrase" |
"boarding pass" |
Searches anywhere (subject, body, etc.) |
from: |
from:amazon.com |
Use sparingly - senders change |
to: |
to:me |
Filter by recipient |
after: |
after:2023/01/01 |
Date threshold (YYYY/MM/DD) |
before: |
before:2024/12/31 |
Date threshold |
newer_than: |
newer_than:30d |
Relative date (d=days, m=months, y=years) |
older_than: |
older_than:1y |
Relative date |
OR |
"shipped" OR "delivered" |
Combine patterns (must be uppercase) |
- |
-category:promotions |
Exclude term |
() |
(a OR b) c |
Grouping |
has:attachment |
has:attachment |
Has any attachment |
is:unread |
is:unread |
Unread messages |
in: |
in:sent |
Folder/label (inbox, sent, trash, spam) |
Email Type Patterns
Tested search phrases that actually appear in real email subject lines.
Travel
Flights (subject-based):
subject:"flight confirmation" OR subject:"your flight" OR subject:"boarding pass" OR
subject:"e-ticket" OR subject:"flight itinerary" OR subject:"flight details" OR
subject:"check-in" OR subject:"ready to fly" OR subject:"trip confirmation" OR
subject:"travel itinerary" OR subject:"flight reservation" OR subject:"itinerary receipt" OR
subject:"e-receipt" OR subject:"travel confirmation"Flights (body-based): Use when subject patterns miss emails with generic subjects.
"confirmation number" OR "booking reference" OR "passenger name" OR
"departure terminal" OR "seat assignment" OR "boarding time" OR
"flight number" OR "check-in opens"Flights (airline-specific terms): Catches formal booking references.
"PNR" OR "record locator" OR "e-ticket number" OR "ticket number" OR "itinerary number"Hotels:
subject:"hotel confirmation" OR subject:"reservation confirmed" OR subject:"your stay" OR
subject:"booking confirmation" OR subject:"your reservation"Car Rental:
subject:"rental confirmation" OR subject:"car reservation" OR subject:"your rental"Commerce
Order Receipts:
subject:"order confirmation" OR subject:"your order" OR subject:"receipt for" OR
subject:"thank you for your order" OR subject:"order #" OR subject:"purchase confirmation"Shipping:
subject:"has shipped" OR subject:"tracking number" OR subject:"out for delivery" OR
subject:"delivered" OR subject:"shipment" OR subject:"your package"Account & Security
Password/Verification:
subject:"reset your password" OR subject:"password reset" OR subject:"verify your email" OR
subject:"confirm your email" OR subject:"verification code"Security Alerts:
subject:"security alert" OR subject:"new sign-in" OR subject:"unusual activity" OR
subject:"suspicious" OR subject:"account security"Financial
Billing/Subscriptions:
subject:"subscription" OR subject:"renewal" OR subject:"billing statement" OR
subject:"invoice" OR subject:"payment received" OR subject:"payment confirmation"Banking:
subject:"statement" OR subject:"transaction" OR subject:"transfer" OR
subject:"direct deposit"Anti-patterns
Don't search by sender for categories:
# BAD: There are hundreds of airlines
from:(united OR delta OR american OR southwest OR jetblue...)
# GOOD: Search by what the email says
subject:"flight confirmation" OR subject:"your flight"Don't use single keywords:
# BAD: Matches "flight of fancy", "fight or flight response", newsletters about flights
flight
# GOOD: Match actual confirmation phrases
subject:"flight confirmation"Don't over-engineer boolean logic:
# BAD: Hard to maintain, easy to get wrong
(subject:flight AND (from:airline OR has:attachment)) OR (subject:itinerary AND -category:promotions)
# GOOD: Simple OR of known patterns
subject:"flight confirmation" OR subject:"your flight" OR subject:"boarding pass"Don't filter in code what inference should judge:
# BAD: Code trying to be smart about relevance
if (email.body.includes("confirmation") && email.from.includes("air")) { ... }
# GOOD: Fetch candidates, let inference decide
// Code: fetch all subject:"flight confirmation" emails
// Inference: "Analyze these emails and identify actual flight bookings"Building Queries
When constructing a search for a specific email type:
- Start with subject patterns - most reliable signal
- Use multiple OR'd phrases - catch variations
- Add date filter - scope the search appropriately
- Skip sender filtering - unless you know the exact domain
- Let inference filter - don't over-constrain
Example for finding flight bookings in the last 3 years:
(subject:"flight confirmation" OR subject:"your flight" OR subject:"boarding pass" OR
subject:"e-ticket" OR subject:"flight itinerary") after:2022/01/01Multi-Pass Search Strategy
For exhaustive searches, run multiple queries with different strategies and deduplicate:
Why multi-pass? Subject patterns are reliable but miss:
- Emails with generic subjects ("Your receipt", "Confirmation")
- Forwarded bookings without original subject
- Booking services that use template subjects
Implementation pattern:
- Pass 1: Subject patterns - most precise, lowest false positives
- Pass 2: Body patterns - catches generic subjects with specific content
- Pass 3: Domain-specific terms - industry jargon (PNR, SKU, etc.)
- Deduplicate by message ID - Gmail IDs are unique
Example for exhaustive flight search:
const queries = [
// Pass 1: Subject patterns
`(subject:"flight confirmation" OR subject:"your flight" OR ...) after:DATE`,
// Pass 2: Body content
`("confirmation number" OR "passenger name" OR "departure terminal") after:DATE`,
// Pass 3: Industry terms
`("PNR" OR "record locator" OR "e-ticket number") after:DATE`,
];
// Run all queries, collect unique IDs, then fetch metadata
const allIds = new Set();
for (const query of queries) {
const ids = await searchGmail(query);
ids.forEach(id => allIds.add(id));
}This approach trades API calls for coverage—essential when completeness matters more than speed.