algolia-core-workflow-b
Implement Algolia indexing pipeline: data sync, partial updates, synonyms, and rules. The secondary money-path workflow: keep your index in sync with source data. Trigger: "algolia indexing", "sync data to algolia", "algolia synonyms", "algolia rules", "algolia partial update", "algolia reindex".
What this skill does
# Algolia Core Workflow B — Indexing & Data Sync
## Overview
Keep your Algolia index synchronized with your source database. Covers full reindex, incremental updates, partial updates, synonyms, and query rules.
## Prerequisites
- Completed `algolia-install-auth` setup
- Familiarity with `algolia-core-workflow-a` (search)
- Source database or API with change tracking (timestamps, events)
## Instructions
### Step 1: Full Reindex with replaceAllObjects
```typescript
import { algoliasearch } from 'algoliasearch';
const client = algoliasearch(process.env.ALGOLIA_APP_ID!, process.env.ALGOLIA_ADMIN_KEY!);
// replaceAllObjects atomically swaps index content
// Internally: creates temp index → indexes all records → moves temp to target
// Search continues on old data until swap is complete — zero downtime
async function fullReindex(records: Record<string, any>[]) {
const { taskID } = await client.replaceAllObjects({
indexName: 'products',
objects: records,
batchSize: 1000, // Records per batch (default 1000)
});
await client.waitForTask({ indexName: 'products', taskID });
console.log(`Full reindex complete: ${records.length} records`);
}
```
### Step 2: Incremental Updates with partialUpdateObject
```typescript
// Only update changed fields — much faster than full saveObjects
async function updateProductPrice(objectID: string, newPrice: number) {
await client.partialUpdateObject({
indexName: 'products',
objectID,
attributesToUpdate: {
price: newPrice,
updated_at: new Date().toISOString(),
},
createIfNotExists: false, // Don't create if missing
});
}
// Batch partial updates
async function syncPriceChanges(changes: { id: string; price: number }[]) {
const { taskID } = await client.partialUpdateObjects({
indexName: 'products',
objects: changes.map(c => ({
objectID: c.id,
price: c.price,
updated_at: new Date().toISOString(),
})),
createIfNotExists: false,
});
await client.waitForTask({ indexName: 'products', taskID });
}
```
### Step 3: Manage Synonyms
```typescript
// Synonyms help users find products with different terminology
await client.saveSynonyms({
indexName: 'products',
synonymHit: [
// Two-way synonym: any of these terms match each other
{
objectID: 'syn-1',
type: 'synonym',
synonyms: ['laptop', 'notebook', 'portable computer'],
},
// One-way synonym: "phone" also searches for "smartphone" but not reverse
{
objectID: 'syn-2',
type: 'oneWaySynonym',
input: 'phone',
synonyms: ['smartphone', 'mobile phone', 'cell phone'],
},
// Alt correction: minor typos/variations
{
objectID: 'syn-3',
type: 'altCorrection1',
word: 'color',
corrections: ['colour'],
},
// Placeholder: replace pattern with alternatives
{
objectID: 'syn-4',
type: 'placeholder',
placeholder: '<size>',
replacements: ['small', 'medium', 'large', 'XL'],
},
],
forwardToReplicas: true,
replaceExistingSynonyms: false, // true = wipe existing first
});
```
### Step 4: Configure Query Rules
```typescript
// Rules let you pin, hide, boost, or filter results for specific queries
await client.saveRule({
indexName: 'products',
objectID: 'rule-sale-banner',
rule: {
conditions: [{
anchoring: 'contains',
pattern: 'sale',
}],
consequence: {
// Pin a specific record to position 1
promote: [{ objectID: 'promo-banner-sale', position: 0 }],
// Add automatic filter
params: {
filters: 'on_sale = true',
},
},
description: 'When user searches "sale", filter to sale items and pin banner',
enabled: true,
},
});
// Hide a product from search results
await client.saveRule({
indexName: 'products',
objectID: 'rule-hide-discontinued',
rule: {
conditions: [{ anchoring: 'is', pattern: '' }], // Matches all queries
consequence: {
hide: [{ objectID: 'discontinued-product-123' }],
},
description: 'Hide discontinued product from all searches',
enabled: true,
},
});
```
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| `Record is too big (limit: 10KB)` | Object exceeds free-tier limit | Strip unnecessary fields; paid plans allow 100KB |
| `Synonym already exists` | Duplicate objectID | Use `replaceExistingSynonyms: true` or unique IDs |
| `Invalid rule condition` | Wrong `anchoring` value | Use `is`, `startsWith`, `endsWith`, or `contains` |
| Partial update creates new record | `createIfNotExists` default is `true` | Set `createIfNotExists: false` |
## Examples
### Database Change Listener → Algolia Sync
```typescript
// Listen for DB changes and push to Algolia
import { getClient } from './algolia/client';
async function onDatabaseChange(event: { type: string; record: any }) {
const client = getClient();
const idx = 'products';
switch (event.type) {
case 'INSERT':
case 'UPDATE':
await client.saveObject({ indexName: idx, body: event.record });
break;
case 'DELETE':
await client.deleteObject({ indexName: idx, objectID: event.record.id });
break;
}
}
```
### Search for Synonyms
```typescript
// List all synonyms matching a query
const { hits } = await client.searchSynonyms({
indexName: 'products',
searchSynonymsParams: { query: 'phone', type: 'synonym' },
});
console.log(`Found ${hits.length} synonym sets matching "phone"`);
```
## Resources
- [Indexing Guide](https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/)
- [Synonyms Guide](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/adding-synonyms/)
- [Rules Guide](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/)
- [replaceAllObjects Reference](https://www.algolia.com/doc/api-reference/api-methods/replace-all-objects/)
## Next Steps
For common errors, see `algolia-common-errors`.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.