search
Status: implemented (services/search, contract: docs/dev/phase4-contracts.md, Search service; specs:
features.md "Search", frontend.md search bar rules). Runs in the apps profile of docker-compose.yml on port
8093 (metrics 9193, :9090 in compose) and is reached through the gateway route /v1/search.
Role: backend of the main search bar. It keeps one OpenSearch document per readable resource, rebuilt from the owning service on every domain event, and answers typo-tolerant queries filtered by the caller's permissions.
Limits: documents hold only what a result needs (title, subtitle, keywords, short descriptions, site, project, ACL fields). Narrowed search bars of the modules (inventory, members…) keep using their own list endpoints.
Flow
Indexed types
type | Source (Kafka topic → REST) | Title / subtitle | Web route |
|---|---|---|---|
member | members.member.v1 → /v1/members/directory?ids= | display name only | /app/members/<id> |
item | inventory.item.v1 → /v1/inventory/items/<id> | name / short code, category, brand model | /app/inventory/<id> |
location | inventory.location.v1 → /v1/inventory/locations/<id> | name / ancestors path | /app/inventory?site=&location=<id> |
event | events.event.v1 → /v1/events/<id> | title / place | /app/events/<id> |
project | projects.project.v1 → /v1/projects/<id> | name / description | /app/projects/<id> |
sheet | borrowing.sheet.v1 → /v1/borrowing/sheets/<id> | member borrower (empty for external borrowers) / purpose | /app/borrowing/<id> |
customer, supplier | finance.customer.v1, finance.supplier.v1 | name / account code; individuals: account code only | /app/finance/customers/<id>, /suppliers/<id> |
quote, invoice | finance.quote.v1, finance.invoice.v1 | number (or subject for drafts) / subject | /app/finance/quotes/<id>, /invoices/<id> |
purchase | finance.purchase.v1 | title | /app/finance/purchases/<id> |
No private PII is indexed: members only by display name (the directory card, no private field is ever fetched), external borrowers never by name, finance individuals only by their pseudonymous account code. Busy (redacted) event views and deleted resources are never indexed.
Indexing
- Consumer (group
search-indexer): every event of the topics above makes the indexer fetch the current resource with the service principal (PRINCIPAL_SIGNING_KEY) and upsert the document, or delete it when the service answers 404 / 410 or the resource is deleted. The aggregate ID is the CloudEvent subject (elsedata.id,data.<type>_id). Unknown event types and payload fields are ignored; malformed events are dropped. - Versioning: writes use OpenSearch external versioning (
external_gte, version = event time in milliseconds), so replays and out-of-order deliveries never overwrite newer data. Delete tombstones are kept one hour (gc_deletes). - Erasure:
members.member.eraseddeletes the member document and removes the ID from every ACL field (creator_id,borrower_id,invitee_ids,member_ids). - Backfill / reindex: a lease job (
search-reindex, checked everyREINDEX_CHECK_INTERVAL) runs pending jobs: it pages through each list endpoint, upserts every document, then deletes the documents of the type not written since the run started (resources deleted while the consumer was behind). A new index requests a backfill automatically;POST /v1/search/reindex(settings.organization.update, auditedsearch.index.reindex) requests one. A type whose service is unreachable is reported infailed_typesand kept as is.
Index
One index (SEARCH_INDEX, default atelier-search) created from an index template:
- analyzers:
folded(standard tokenizer, French elision, lowercase, ASCII folding),french_folded(+ French stop words and light stemming),edge(edge n-grams 2–20, index time only); titleis asearch_as_you_typefield (+title.fr,title.edge);subtitle,keywords(+keywords.edge, normalisedkeywords.exact),body(descriptions, low weight);- filter fields:
type,id,site_id,project_id,acl.*; sort tie breakerkey(<type>:<id>).
Query
GET /v1/search?q=&types=&limit=&cursor= (see the API reference):
q: 2 to 200 characters (whitespace collapsed);types: comma list (all by default);limit: default 10, capped at 20;cursor:next_cursorof the previous page (search_afteron score + key).- Relevance: prefix on the last word (
bool_prefixon the search-as-you-type fields), fuzzy match (AUTOedit distance, first letter exact) on titles, subtitles, keywords and descriptions, edge n-grams, and a strong boost for exact codes (A-7K3QZ0MD,F-PAR-2026-0001). - Access: one filter per type, combined with OR. The scopes come from authz
LookupResources(all, sites, projects, IDs), fetched concurrently once per request (plusSubjectRoleswhen events are searched).
| Type | Visible when |
|---|---|
member | any authenticated user; API keys and services: members.member.read scope |
item, location | inventory.item.read, inventory.location.read scope |
event | public; creator; invited user, global role or project role; events.event.update scope (manage_all in admin mode); events.event.read_private scope when the event invites read_private holders |
project | projects.project.read scope (+ read_all in admin mode) or project member |
sheet | borrowing.sheet.read scope (+ read_all in admin mode), member borrower or creator |
customer, supplier, quote, invoice | finance.<type>.read scope |
purchase | finance.purchase.read scope or requester |
The response keeps the shape used by the web client: {items: [{type, id, title, subtitle, url}], next_cursor}.
Rate limiting stays in the gateway.
Data
OpenSearch index (documents) and MongoDB search (jobs reindex state, locks, outbox for audit records).
Environment
| Variable | Default | Purpose |
|---|---|---|
HTTP_ADDR / METRICS_ADDR | :8093 / :9193 | Listeners |
OPENSEARCH_URL | http://localhost:9200 | OpenSearch nodes (comma-separated) |
SEARCH_INDEX | atelier-search | Index and template name |
MONGO_URI, MONGO_DATABASE | search | Job state, leases, outbox |
AUTHZ_URL | localhost | Scopes and roles |
MEMBERS_URL, INVENTORY_URL, EVENTS_URL, PROJECTS_URL, BORROWING_URL, FINANCE_URL | localhost ports | Resource reads |
PRINCIPAL_PUBLIC_KEY, PRINCIPAL_SIGNING_KEY | required | Verify callers, sign the service principal |
REINDEX_CHECK_INTERVAL | 30s | Backfill job period |
FETCH_TIMEOUT | 10s | Upstream call timeout |
Tests: unit tests with fakes, integration tests with an OpenSearch container (opensearchproject/opensearch:3.9.0,
security plugin disabled; OPENSEARCH_TEST_URL reuses a running node), mongotest and kafkatest, all skipped
with -short.