Safety: With no filters, relation deletion uses a safe match‑all filter
id:!=null. Prefer targeted filters; consider Indexer → Stale Deletes for recurring cleanup flows with guardrails.Relation‑level: delete_all
- Compiles current
whereAST tofilter_byand sendsDELETE /documents. - When the relation has no predicates, falls back to
id:!=null(match‑all). - Options:
into:physical collection name (skip alias resolution)partition:forwarded to the resolver (see below)timeout_ms:read timeout override for the delete call
Flow
Model‑level: delete_by
Use either a filter string or a Hash that will be converted safely.- Provide either a non‑blank String or a non‑empty Hash. An empty input raises.
into:overrides the target physical collection.partition:is passed to the resolver (see next section).- Return value is the number of deleted documents the server reports.
Instance‑level: delete (single record)
Delete a single hydrated record by its document id.- The record id is taken from hydrated
idwhen present, otherwise computed via the model’sidentify_bystrategy. - If the id cannot be determined, an error is raised.
- Calling
deleteon a Relation is not supported; usedelete_all.
Low‑level helper: SearchEngine::Deletion.delete_by
Into resolution
The target collection is resolved in order:- Explicit
into:option when provided - Contextual
intofrom instrumentation (used during schema apply/indexation) SearchEngine.config.partitioning.default_into_resolverif configured- Fallback to the model’s logical collection name (
klass.collection)
Timeouts
timeout_ms: overrides the read timeout. When omitted, it falls back to
SearchEngine.config.stale_deletes.timeout_ms when set; otherwise the client default is used.
When to use Indexer stale deletes
Prefer Indexer → Stale Deletes when you routinely delete by a known filter. It offers:- Centralized
stalerules on the model (declared insideindex) - Strict‑mode guardrails to block suspicious catch-alls
- Optional estimation and events for observability
Troubleshooting
- Empty input:
delete_byrequires a filter string or a non‑empty hash - Deleted 0 docs unexpectedly: check
into:(physical vs alias) and filter - Partitioned setups: pass
partition:so your resolver can pick a target - Timeouts: increase
timeout_msfor large deletes