Skip to content
Skillv1.0.0

algolia-upgrade-migration

Upgrade algoliasearch from v4 to v5 with breaking change detection and codemod. Use when upgrading SDK versions, detecting deprecations, or migrating initIndex patterns. Trigger: "upgrade algolia", "a

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (skills/.curated/algolia-upgrade-migration/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill algolia-upgrade-migration. Copyright stays with the author (MIT).

Algolia Upgrade & Migration (v4 to v5)

Overview

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.

Prerequisites

  • Current algoliasearch v4 installed
  • Git for version control (work in a branch)
  • Test suite passing on current version

Breaking Changes Summary

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 })

Instructions

Examples

The upgrade steps are concrete v4-to-v5 examples: replace client initialization and method calls, then run the search and type-check suite before widening rollout. Keep the pre-upgrade branch available until production verification succeeds.

Step 1: Create Upgrade Branch and Install v5

git checkout -b upgrade/algoliasearch-v5
npm install algoliasearch@latest
npm list algoliasearch  # Verify v5.x.x

Step 2: Update Imports

// 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';

Step 3: Remove initIndex and Update Method Calls

// 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'] },
});

Step 4: Update waitTask

// 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 });

Step 5: Update Error Handling

// 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}`);
  }
}

Step 6: Find All Usage and Verify

# 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

Rollback Procedure

# If v5 breaks things, revert to v4
npm install algoliasearch@4
git checkout -- src/  # Restore v4 code
npm test              # Verify v4 still works

Output

The codebase uses the v5 client API with verified imports, parameter shapes, and task waiting, while retaining a tested rollback procedure to the prior package version and source revision.

Error Handling

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 }

Resources

Next Steps

For CI integration during upgrades, see algolia-ci-integration.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-algolia-upgra-af9561/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-algolia-upgra-af9561.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-algolia-upgra-af9561",
  "kind": "skill",
  "name": "algolia-upgrade-migration",
  "description": "Upgrade algoliasearch from v4 to v5 with breaking change detection and codemod. Use when upgrading SDK versions, detecting deprecations, or migrating initIndex patterns. Trigger: \"upgrade algolia\", \"algolia migration v5\", \"algolia breaking changes\", \"update algolia SDK\", \"algolia v4 to v5\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "saas",
      "search",
      "algolia",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Upgrade algoliasearch from v4 to v5 with breaking change detection and codemod. Use when upgrading SDK versions, detecting deprecations, or migrating initIndex patterns. Trigger: \"upgrade algolia\", \"algolia migration v5\", \"algolia breaking changes\", \"update algolia SDK\", \"algolia v4 to v5\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "skills/.curated/algolia-upgrade-migration/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/skills/.curated/algolia-upgrade-migration/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/skills/.curated/algolia-upgrade-migration/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit,",
      "Bash(npm:*),",
      "Bash(git:*),",
      "Bash(npx:*),",
      "Grep"
    ],
    "license": "MIT"
  },
  "instructions": "# Algolia Upgrade & Migration (v4 to v5)\n\n## Overview\n\nGuide 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.\n\n## Prerequisites\n\n- Current `algoliasearch` v4 installed\n- Git for version control (work in a branch)\n- Test suite passing on current version\n\n## Breaking Changes Summary\n\n| v4 Pattern | v5 Replacement |\n|-----------|----------------|\n| `const client = algoliasearch(appId, key)` | `import { algoliasearch } from 'algoliasearch'; const client = algoliasearch(appId, key)",
  "cost": {
    "context_tokens": 1391
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-algolia-upgra-af9561/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.