Quickstart
This guide goes from nothing to search results. You create an index, add three product records, check that they’re live, and search them.
Captain gives you three keys at onboarding, along with your tenant’s endpoint: a search key, a write key and an issuer key. The write key creates indexes and adds records, and it stays on your server. The search key runs searches and reads the index’s analytics, so keep it on your server too. The issuer key mints short-lived scoped keys, and it stays on your server as well. In a browser or an app, use a scoped key limited to your site with allowed_origins. The examples use the tenant acme. Replace it with the endpoint from onboarding.
1. Create an index
An index holds one kind of record, such as products, articles or listings. Give it a name of lowercase letters, digits, dashes and underscores.
curl
Python
TypeScript
The new index is empty until records arrive. Field types are optional. When you leave them out, Captain types each field from the first records you add. To set them yourself, see Create Index and the field types in Records.
2. Add records
Send records as a JSON array. Each record needs an id and the fields you want search to know about.
curl
Python
TypeScript
The reply confirms that three new records were accepted, and gives the change a seq number. Records become searchable within a few seconds. There’s no separate build step.
3. Check the records are live
Get Update Status reports the last change search has applied. When applied_seq reaches the seq from step 2, the records are live.
curl
Python
TypeScript
In an app, you rarely need this check. It’s useful in a script that adds records and then searches them straight away.
4. Run a search
Searches use the search key. Send the words people type as query.
curl
Python
TypeScript
The reply lists results under hits, best first. Each hit carries the record’s id, its fields and a relevance score. total is an estimate of how many records matched, not an exact count, so page with page.has_more rather than total. Send "exact_total": true when you need a count to show, and check total_exact in the reply. timing.engine_ms is how long Captain took to answer, in milliseconds.
5. Add a filter
A filter keeps only the records that meet every condition. List Filters shows which fields you can filter on and which operators each one accepts.
curl
Python
TypeScript
Only the Merrell boot is both from one of the two brands and at or under $150, so it’s the one result.
6. Count facets
Facets count how many results have each value of a field, which is what a sidebar of brand or category checkboxes needs.
curl
Python
TypeScript
facets in the reply holds the count for each value of each requested field.