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 two keys at onboarding, along with your tenant’s endpoint. The write key creates indexes and adds records, and it stays on your server. The search key runs searches, and it’s safe to use in a browser or an app. 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 counts every matching record, and timing reports where the time went.
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.