Overview
Use the update helpers when you need to patch existing documents in Typesense without re-mapping the full dataset. These APIs reuse the compiled schema and validation path, and respect partition/alias resolution. Related: Upsert, Deletion, Indexer.APIs
Instance: SearchEngine::Base#update
- Partially updates a hydrated record (uses its document id or
identify_byfallback). - Signature:
record.update(attrs, into: nil, partition: nil, timeout_ms: nil, cascade: nil). - Returns
1on success,0if nothing was updated.
cascade: truetriggers a best-effort cascade reindex of referencing collections.- Fails when the id cannot be determined; include
idin selection or defineidentify_by.
Relation: SearchEngine::Relation#update_all
- Updates all documents matching the current relation filters.
- Signature:
rel.update_all(attrs, into: nil, partition: nil, timeout_ms: nil). - Empty relation filters fall back to a safe match-all
id:!=null.
Low-level: SearchEngine::Update.update_by
- Filter-driven update without a relation.
- Signature:
Update.update_by(klass:, attributes:, filter: nil, hash: nil, into: nil, partition: nil, timeout_ms: nil). - Accepts either a Typesense filter string (
filter:) or a Hash converted via the Sanitizer (hash:).
Options & Resolution
into:— override physical collection; defaults to alias or partition resolver.partition:— forwarded to partition resolver and cascade contexts.timeout_ms:— optional read timeout override for the update request.
When to use vs upsert/indexer
- Use update: targeted patches to a known set of documents; small scope; you already know ids or filters.
- Use upsert: when you need to re-map source records (ActiveRecord/SQL) or send pre-mapped hashes with schema validation.
- Use indexer: for large-scale rebuilds, partitioned workflows, or when schema drift needs to be handled.
Safety tips
- Provide explicit filters; match-all is allowed but should be intentional.
- Keep payloads small; Typesense applies the provided fields as partial updates.
- Combine with
timeout_msfor long-running operations, and considercascade: trueon instance updates when referencers exist.