This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendhigh PriorityID: meilisearch-fulltext-engine

Meilisearch Fast Full-Text Search & Filterable Attributes Standard

Production search engine standard for Meilisearch. Mandates explicit index configuration (searchableAttributes, filterableAttributes, rankingRules), asynchronous task UID completion polling with waitForTask(), and tenant-scoped search keys.

Prohibited Anti-Pattern: AI filters Meilisearch queries without declaring filterableAttributes, triggering un-indexed search query failures.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Meilisearch Fast Full-Text Search & Filterable Attributes Standard - Production search engine standard for Meilisearch. Mandates explicit index configuration (searchableAttributes, filterableAttributes, rankingRules), asynchronous task UID completion polling with waitForTask(), and tenant-scoped search keys.
globs: **/*meili*.ts, **/*search*.ts, **/*search*.py
alwaysApply: false
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/meilisearch-fulltext-engine"
---

# Meilisearch Fast Full-Text Search & Filterable Attributes Standard

> **Severity**: HIGH | **Category**: backend
> **Anti-Pattern Warning**: AI filters Meilisearch queries without declaring filterableAttributes, triggering un-indexed search query failures.

## System Constraints
You are a search systems and retrieval specialist. In Meilisearch integrations, NEVER filter on fields without first declaring them in index.updateFilterableAttributes(). Always poll asynchronous indexing tasks with client.waitForTask(taskUid) and generate scoped tenant search tokens for multi-tenant isolation.

## Strict Guidelines
- Declare searchableAttributes, filterableAttributes, and sortableAttributes explicitly during application startup or migrations.
- Always await client.waitForTask(task.taskUid) during migrations to verify asynchronous schema updates have succeeded before querying.
- Generate scoped search keys with tenant filters using client.generateTenantToken() to prevent unauthorized cross-tenant data access.
- Order rankingRules appropriately (words, typo, proximity, attribute, sort, exactness) to tune domain search relevance.

## Bad vs Good Implementations
### Index Settings Configuration & Task Await vs Un-indexed Filter Failure

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Meilisearch rejects filtered queries on undeclared attributes by design to prevent un-indexed performance regressions.
```typescript
// ANTI-PATTERN: Querying filters without configuring filterableAttributes
const index = client.index("products");
await index.addDocuments(documents);
// FAILS: Attribute category is not filterable!
const results = await index.search("laptop", { filter: 'category = "Electronics"' });
```

#### Production Standard (Correct)
> **Standard**: Pre-computes inverted index trees and bitset filters for sub-10ms response times on millions of records.
```typescript
// PRODUCTION STANDARD: Explicit Index Initialization & Task Completion Wait
import { MeiliSearch } from "meilisearch";
const client = new MeiliSearch({ host: "http://meilisearch.internal:7700", apiKey: process.env.MEILI_KEY });

export async function initProductsIndex() {
  const index = client.index("products");
  const settingsTask = await index.updateSettings({
    searchableAttributes: ["title", "description", "brand"],
    filterableAttributes: ["category", "inStock", "organizationId"],
    sortableAttributes: ["price", "createdAt"],
    rankingRules: ["words", "typo", "proximity", "attribute", "sort", "exactness"],
  });
  await client.waitForTask(settingsTask.taskUid);
}
```

### Multi-Tenant Scoped Search Token Generation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Malicious users can tamper with filter parameters in client-side code to access competing tenants' records.
```typescript
// ANTI-PATTERN: Passing user-controlled tenant filters in public frontend search requests
const results = await index.search(query, { filter: `orgId = "${userOrgId}"` });
```

#### Production Standard (Correct)
> **Standard**: Enforces tenant boundary isolation cryptographically, permitting safe client-to-engine direct search.
```typescript
// PRODUCTION STANDARD: Cryptographically signed tenant token with embedded rules
const tenantToken = client.generateTenantToken({
  searchRules: { products: { filter: `organizationId = "${authenticatedUser.orgId}"` } },
  expiresAt: new Date(Date.now() + 3600 * 1000),
});
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Meilisearch Fast Full-Text Search & Filterable Attributes Standard

Meilisearch Fast Full-Text Search & Filterable Attributes Standard defines an industrial-grade behavioral standard for backend engineering. Production search engine standard for Meilisearch. Mandates explicit index configuration (searchableAttributes, filterableAttributes, rankingRules), asynchronous task UID completion polling with waitForTask(), and tenant-scoped search keys. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: AI filters Meilisearch queries without declaring filterableAttributes, triggering un-indexed search query failures. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAI filters Meilisearch queries without declaring filterableAttributes, triggering un-indexed search query failures.High
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Declare searchableAttributes, filterableAttributes, and sortableAttributes explicitly during application startup or migrations.

Declare searchableAttributes, filterableAttributes, and sortableAttributes explicitly during application startup or migrations.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Always await client.waitForTask(task.taskUid) during migrations to verify asynchronous schema updates have succeeded before querying.

Always await client.waitForTask(task.taskUid) during migrations to verify asynchronous schema updates have succeeded before querying.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Generate scoped search keys with tenant filters using client.generateTenantToken() to prevent unauthorized cross-tenant data access.

Generate scoped search keys with tenant filters using client.generateTenantToken() to prevent unauthorized cross-tenant data access.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Order rankingRules appropriately (words, typo, proximity, attribute, sort, exactness) to tune domain search relevance.

Order rankingRules appropriately (words, typo, proximity, attribute, sort, exactness) to tune domain search relevance.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Meilisearch Fast Full-Text Search & Filterable Attributes Standard critical for AI coding assistants?

Production search engine standard for Meilisearch. Mandates explicit index configuration (searchableAttributes, filterableAttributes, rankingRules), asynchronous task UID completion polling with waitForTask(), and tenant-scoped search keys. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (AI filters Meilisearch queries without declaring filterableAttributes, triggering un-indexed search query failures.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Meilisearch