CtrlK
BlogDocsLog inGet started
Tessl Logo

creativecodeology/meilisearch

Meilisearch search engine integration with the JavaScript/TypeScript SDK (v0.44+). Use when working with Meilisearch indexes, search queries, filters, facets, sorting, multi-search, tenant isolation, document sync, or search settings configuration. Triggers on: meilisearch client setup, index creation, addDocuments, search with filters, facetDistribution, tenant tokens, multi-search, ranking rules, filterable/sortable/searchable attributes. Use this skill any time the user mentions Meilisearch, search indexing, full-text search in their app, or asks about tenant-scoped search — even for simple tasks like 'add search to this page', because the skill contains critical multi-tenancy and filter syntax patterns that prevent data leaks.

94

Quality

94%

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

error-handling.mdreferences/

Error Handling and Reliability

MeiliSearchApiError

The SDK throws MeiliSearchApiError for API-level errors. It contains structured error information.

import { MeiliSearchApiError } from "meilisearch";

try {
  await index.search("query", { filter: 'bad_field = "value"' });
} catch (error) {
  if (error instanceof MeiliSearchApiError) {
    console.error(error.code);    // e.g., "invalid_search_filter"
    console.error(error.message); // Human-readable description
    console.error(error.type);    // "invalid_request" | "internal" | "auth"
    console.error(error.link);    // Link to docs for this error
  }
}

Common Error Codes

CodeMeaningFix
index_not_foundIndex doesn't existCreate it with client.createIndex() first
invalid_search_filterFilter syntax error or attribute not filterableCheck filter syntax and filterableAttributes
invalid_search_sortSort attribute not declared sortableAdd to sortableAttributes
invalid_document_idPrimary key value is invalidMust be string or integer, no special chars
missing_document_idDocument missing primary key fieldEnsure every document has the primary key
invalid_api_keyAuthentication failedCheck API key permissions and expiration
immutable_api_key_uidTried to change a key's UIDUIDs are assigned at creation, can't be changed
document_fields_limit_reachedToo many fields in a documentMeilisearch has a 65,535 field limit per index

Task Errors

Write operations return tasks. Tasks can fail asynchronously.

const { taskUid } = await index.addDocuments(docs);
const task = await client.waitForTask(taskUid);

if (task.status === "failed") {
  console.error(task.error);
  // { message: "...", code: "...", type: "...", link: "..." }
}

Always check task status after waitForTask — it resolves when the task finishes, whether it succeeded or failed.

Retry Patterns

Meilisearch write operations are idempotent (same document with same ID = safe to retry), so retries are safe for network errors.

async function withRetry<T>(
  fn: () => Promise<T>,
  maxRetries = 3,
  delayMs = 1000,
): Promise<T> {
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    try {
      return await fn();
    } catch (error) {
      if (attempt === maxRetries) throw error;

      // Only retry on network/timeout errors, not validation errors
      if (error instanceof MeiliSearchApiError) {
        if (error.type === "invalid_request") throw error; // Don't retry bad input
      }

      await new Promise((r) => setTimeout(r, delayMs * 2 ** attempt));
    }
  }
  throw new Error("unreachable");
}

Health Check

try {
  const health = await client.health();
  // { status: "available" }
} catch {
  // Meilisearch is down or unreachable
}

Use this in readiness probes, not in hot paths.

Connection Errors

The SDK throws generic Error (not MeiliSearchApiError) for connection failures (ECONNREFUSED, timeout). Handle both:

try {
  await index.search("query");
} catch (error) {
  if (error instanceof MeiliSearchApiError) {
    // API-level error (bad filter, auth failure, etc.)
  } else {
    // Connection-level error (Meilisearch unreachable)
  }
}

references

advanced-search.md

error-handling.md

SKILL.md

tile.json