Algolia compatibility
Each tenant also answers Algolia’s search and indexing routes, so an existing Algolia client or InstantSearch front end can search Captain, and your Algolia indexing code can keep Captain’s copy up to date:
These routes read and write Captain’s copy of the index. They never forward requests to Algolia.
Setup
- Import the Algolia index into Captain under the same index name. See Import from Algolia.
- Point the Algolia client at the tenant host,
acme.captain.dev. - Pass a Captain search key where the client expects the Algolia API key, or a write key for indexing. The write routes also take the key as
Authorization: Bearer.
The application id can be any value. The hostname selects the tenant.
Point the Algolia client at Captain
The JavaScript client takes the tenant host in hosts. The same client works with InstantSearch.
Multi-query
Each request names an index and its Algolia search parameters. The reply holds one result per request, in Algolia’s format.
curl
Python
TypeScript
Single-index query
curl
Python
TypeScript
Insights events
Send clicks and conversions with the queryID from the search result. They feed the same analytics as the native events route.
curl
Python
TypeScript
Indexing with an Algolia client
Writes take a Captain write key where the client expects the Algolia API key. Keep it on your server, as you would Algolia’s admin key.
Each write runs as the Captain write it maps to, so it takes effect as fast and fails the same way:
addObject,updateObjectandsaveObjectadd or replace whole records, as Add Records does.partialUpdateObjectchanges the attributes you send, as Update Records does. WithcreateIfNotExists(the default), an object the index doesn’t have is added. Built-in operations such asIncrementorAddanswer400. Send the new value instead.deleteObjectdeletes, and an objectID the index doesn’t have is not an error. AdeleteObjectwith noobjectIDanswers400.clearObjectsempties the index and keeps its settings.deleteIndexdeletes the index, with the same key rule as Delete Index.
A write to an index that doesn’t exist creates it, as Algolia does, keyed by objectID. That needs a write key for every index. objectID is always the record’s id. On an index created with "id_field": "objectID", every other attribute is stored as you send it, an id attribute included. On an index keyed by another field (id by default), Captain stores the objectID in that field, and an object whose own value there is different answers 400 ID_CONFLICT and nothing from the request is saved. This keeps objects that share a value apart. Shopify records, for example, carry the variant in objectID and the product in id: send them to an index created with "id_field": "objectID" so each variant stays its own record.
taskID is the write’s seq. waitTask reports published once search has applied the write, which Get Update Status reports as applied_seq.
Settings, synonyms and rules through the /1 routes (setSettings, saveSynonyms, saveRules), and deleteBy, aren’t mapped. Those answer 501. Change settings with Update Settings, and delete by filter with Delete Records By Filter.
Limits
- Supported client versions, headers and parameters are validated per integration before a migration goes live.
- Indexes with per-record access control are not served on these routes. Use the native search routes with scoped keys.
- Facet counts are exact while a query matches up to 250 records. Above that they cover the relevance-cut result set, and the reply says
exhaustiveFacetsCount: false, as Algolia does on large result sets.