Architecture
The search system is implemented in/internal/search/search.go and uses an event-driven indexing model:
- Automatic Indexing: Records are indexed asynchronously via queue
- Batch Indexing: Dependencies (balances) are indexed before primary records (transactions)
- Schema Migration: Automatic schema updates when new fields are added
- Reindexing: Full reindex capability for initial setup or recovery
Collections
Blnk maintains five Typesense collections:| Collection | Purpose | Key Fields |
|---|---|---|
ledgers | Ledger accounts | ledger_id, name, created_at |
balances | Balance records | balance_id, balance, currency, ledger_id |
transactions | Transaction history | transaction_id, reference, status, amount |
reconciliations | Reconciliation jobs | reconciliation_id, status, matched_transactions |
identities | Customer identities | identity_id, first_name, email_address |
Collection Schemas
Schemas are defined in search.go:524-660 and include: Transactions Schema:- All fields are facetable for filtering
- References between collections (e.g., transactions → balances)
- Nested object support for metadata
- Timestamp fields as Unix timestamps for range queries
Configuration
Typesense Connection
Configure Typesense in yourblnk.json:
Docker Deployment
Run Typesense alongside Blnk:Indexing Operations
Automatic Indexing
Records are indexed automatically via the queue system:Batch Indexing
Dependency-aware batch indexing ensures referential integrity:Search API
Basic Search
Search across collections using the Blnk API:Advanced Filtering
Date Range Queries:Multi-Search
Search across multiple collections simultaneously:Reindexing
Reindex all data from PostgreSQL to Typesense.Triggering a Reindex
Via API:Monitoring Progress
Reindex Process
The reindex operation follows this sequence (reindex.go:90-142):- Drop Collections: Remove existing collections
- Create Collections: Recreate with latest schemas
- Index Ledgers: Index all ledger accounts
- Index Identities: Index customer identities
- Index Balances: Index all balance records
- Index Transactions: Index all transactions
Automatic Reindex on Startup
Blnk automatically reindexes if:- Database has data
- Typesense is empty
Schema Migration
Typesense schemas can be updated without reindexing:Performance Tuning
Batch Size Configuration
Optimal batch sizes for reindexing:- Small datasets (< 100K records): 1000
- Medium datasets (100K - 1M records): 5000
- Large datasets (> 1M records): 10000
Typesense Memory Settings
Configure Typesense memory based on index size:- 1M documents ≈ 500MB RAM
- 10M documents ≈ 5GB RAM
- 100M documents ≈ 50GB RAM
Query Performance
Use Field Weighting:Best Practices
- Enable Automatic Indexing: Ensure queue system is running for real-time index updates
-
Schedule Reindexing: Run full reindex during low-traffic periods
-
Monitor Index Health: Check collection stats regularly
-
Use Precise Filters: Narrow searches with filters before full-text search
-
Backup Typesense Data: Regular snapshots of
/datadirectory
Troubleshooting
Search Returns No Results
Check Collection Exists:Slow Search Queries
Enable Query Logging:- Avoid wildcard prefix searches (
*john) - Use filters to narrow result set
- Reduce
per_pagesize
Reindex Failures
Check Logs:- Invalid field types (e.g., string in int64 field)
- Missing required fields
- Typesense connection timeout