From algolia-pack
Upgrades algoliasearch from v4 to v5: detects breaking changes, replaces initIndex patterns, updates imports/methods like search/saveObjects. Use for SDK migrations.
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin algolia-packThis skill is limited to using the following tools:
Guide for upgrading `algoliasearch` from v4 to v5. The v5 release is a major rewrite: `initIndex()` is removed, all methods move to the client, and the import style changes.
Implements algoliasearch v5 patterns: singleton client, typed search, error handling, batch operations. For Algolia integrations, SDK refactoring, team standards.
Provides patterns for Algolia search implementation using React InstantSearch hooks, indexing strategies, relevance tuning, and Next.js SSR integration.
Guides framework and language migrations: version upgrades, breaking changes, dependency audits, codemods, rollbacks for React 19, Vue 3, Next.js, Laravel 11, Python 3.12, Node 22.
Share bugs, ideas, or general feedback.
Guide for upgrading algoliasearch from v4 to v5. The v5 release is a major rewrite: initIndex() is removed, all methods move to the client, and the import style changes.
algoliasearch v4 installed| v4 Pattern | v5 Replacement |
|---|---|
const client = algoliasearch(appId, key) | import { algoliasearch } from 'algoliasearch'; const client = algoliasearch(appId, key); |
const index = client.initIndex('name') | Removed — pass indexName to every method |
index.search('query') | client.searchSingleIndex({ indexName, searchParams: { query } }) |
index.saveObjects(records) | client.saveObjects({ indexName, objects }) |
index.saveObject(record) | client.saveObject({ indexName, body: record }) |
index.partialUpdateObject(data) | client.partialUpdateObject({ indexName, objectID, attributesToUpdate }) |
index.deleteObject('id') | client.deleteObject({ indexName, objectID }) |
index.setSettings(settings) | client.setSettings({ indexName, indexSettings }) |
index.getSettings() | client.getSettings({ indexName }) |
index.browse() | client.browse({ indexName, browseParams }) |
index.findObject(cb) | client.findObject({ indexName, ... }) |
index.replaceAllObjects(records) | client.replaceAllObjects({ indexName, objects }) |
index.saveSynonyms(syns) | client.saveSynonyms({ indexName, synonymHit }) |
index.saveRule(rule) | client.saveRule({ indexName, objectID, rule }) |
index.waitTask(taskID) | client.waitForTask({ indexName, taskID }) |
git checkout -b upgrade/algoliasearch-v5
npm install algoliasearch@latest
npm list algoliasearch # Verify v5.x.x
// v4
import algoliasearch from 'algoliasearch';
const client = algoliasearch('APP_ID', 'API_KEY');
// v5
import { algoliasearch } from 'algoliasearch';
const client = algoliasearch('APP_ID', 'API_KEY');
// v5 lite client (search-only, frontend)
import { liteClient } from 'algoliasearch/lite';
const searchClient = liteClient('APP_ID', 'SEARCH_KEY');
// v5 individual API client (if you only need one)
import { searchClient } from '@algolia/client-search';
// v4: index-based API
const index = client.initIndex('products');
const { hits } = await index.search('laptop');
await index.saveObjects(records);
await index.setSettings({ searchableAttributes: ['name'] });
// v5: client-based API with indexName parameter
const { hits } = await client.searchSingleIndex({
indexName: 'products',
searchParams: { query: 'laptop' },
});
await client.saveObjects({ indexName: 'products', objects: records });
await client.setSettings({
indexName: 'products',
indexSettings: { searchableAttributes: ['name'] },
});
// v4
const { taskID } = await index.saveObjects(records);
await index.waitTask(taskID);
// v5
const { taskID } = await client.saveObjects({ indexName: 'products', objects: records });
await client.waitForTask({ indexName: 'products', taskID });
// v4: error classes from algoliasearch
import { AlgoliaError } from 'algoliasearch';
// v5: error classes
import { ApiError } from 'algoliasearch';
try {
await client.searchSingleIndex({ indexName: 'products', searchParams: { query: 'test' } });
} catch (error) {
if (error instanceof ApiError) {
console.error(`HTTP ${error.status}: ${error.message}`);
}
}
# Find all files using Algolia v4 patterns
grep -rn "initIndex\|\.search(\|\.saveObjects\|\.setSettings\|\.deleteObject\|\.waitTask" \
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" src/
# Run tests
npm test
# Type-check
npx tsc --noEmit
# If v5 breaks things, revert to v4
npm install algoliasearch@4
git checkout -- src/ # Restore v4 code
npm test # Verify v4 still works
| Issue | Cause | Solution |
|---|---|---|
initIndex is not a function | v5 installed but v4 code | Remove initIndex, pass indexName to methods |
searchSingleIndex is not a function | v4 installed but v5 code | Run npm install algoliasearch@latest |
| Type errors after upgrade | Changed type signatures | Update to new parameter objects |
default import error | v5 uses named exports | Change import algoliasearch to import { algoliasearch } |
For CI integration during upgrades, see algolia-ci-integration.