Skip to content

Searching Documents

Auth required: Authorization: <main_api_key> or Authorization: <search_api_key> header.

Multi-word queries perform an AND search. Only documents matching all terms are returned. Results include the full stored JSON document for each match.

Cursor-based pagination

Omit after for the first page, then pass the last result's id as after for subsequent pages. In desc mode, after filters IDs lower than the cursor; in asc mode, it filters IDs higher.

Example

Search results return the full stored document for each match, including all fields that were provided at upsert time.

js
const { results, take, elapsed_ms } = await client.search("posts", {
  q: "hello world",
  sort: "asc",
  take: 50,
  after: "01HQ8C3Y",
});
js
const params = new URLSearchParams({
  q: "hello world",
  sort: "asc",
  take: "50",
  after: "01HQ8C3Y",
});
const res = await fetch(`http://localhost:3000/collections/posts/search?${params}`, {
  headers: { Authorization: "SecretApiKey" },
});
const { results, take, elapsed_ms } = await res.json();
sh
# GET /collections/{collection_name}/search?q=query_term
#
# Response: 200 OK
# {
#   "results": [
#     {"id": "01HPT7B2X...", "title": "Hello", "body": "..."},
#     {"id": "01HQ8C3Y...", "title": "World", "body": "..."}
#   ],
#   "take": 20,
#   "elapsed_ms": 1.234
# }

curl "http://localhost:3000/collections/posts/search?q=hello+world&sort=asc&take=50&after=01HQ8C3Y" \
  -H "Authorization: SecretApiKey"

Endpoint Definition

FieldValue
MethodGET
Path/collections/{collection}/search

Query Parameters

ParamTypeDefaultDescription
qstringSearch query (one or more terms, space-separated)
sortstringdescSort by ID: asc or desc
takeinteger20Max results (clamped 1 – 100)
afterstringExclusive cursor ID for cursor-based pagination

Response Body

FieldTypeDescription
resultsarray of objectMatching documents (full stored JSON objects)
takeintegerNumber of results returned
elapsed_msnumberTime spent executing the search, in milliseconds

Response: 200 OK