Skip to content

feat(index): add compact() method for index compaction#2133

Draft
mixelburg wants to merge 4 commits into
meilisearch:mainfrom
mixelburg:feat/compact-database
Draft

feat(index): add compact() method for index compaction#2133
mixelburg wants to merge 4 commits into
meilisearch:mainfrom
mixelburg:feat/compact-database

Conversation

@mixelburg

@mixelburg mixelburg commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds support for the index compaction API introduced in Meilisearch v1.23 (reference).

Changes

  • Added compact() method to the Index class — calls POST /indexes/{indexUid}/compact
  • Added tests/compact.test.ts with permission, auth denial, and URL construction test cases
  • Added compact_index_1 code sample to .code-samples.meilisearch.yaml

Usage

// Trigger compaction and wait for it to complete
const task = await client.index('movies').compact().waitTask();
console.log(task.status); // 'succeeded'

Closes

Closes #2066

Summary by CodeRabbit

  • New Features
    • Added an API to compact indexes, helping optimize storage and improve performance.
  • Documentation
    • Included an additional code sample showing how to run index compaction.
  • Tests
    • Added end-to-end tests for index compaction, including permission handling (success and failure), error propagation, and host/URL construction behavior.

Closes meilisearch#2066

Implements the `POST /indexes/{indexUid}/compact` endpoint introduced
in Meilisearch v1.23. Compaction reorganizes the index database to
reclaim space and improve read performance.

Example:
```ts
await client.index('movies').compact().waitTask();
```
@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aedd6773-8255-4371-8247-b96a459abe73

📥 Commits

Reviewing files that changed from the base of the PR and between f656c8e and e26a0a8.

📒 Files selected for processing (2)
  • .code-samples.meilisearch.yaml
  • src/indexes.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/indexes.ts
  • .code-samples.meilisearch.yaml

📝 Walkthrough

Walkthrough

Adds Index.compact() to enqueue index compaction, plus a matching code sample and end-to-end tests for access control and request routing.

Changes

Index compaction support

Layer / File(s) Summary
Compaction API, sample, and tests
src/indexes.ts, .code-samples.meilisearch.yaml, tests/compact.test.ts
Adds Index.compact() as a POST to indexes/{uid}/compact, includes a client.index('movies').compact() sample, and adds E2E coverage for success, auth failures, and host/URL handling.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client
    participant Index
    participant HTTP
    participant MeiliSearch
    Client->>Index: client.index('movies').compact()
    Index->>HTTP: POST /indexes/movies/compact
    HTTP->>MeiliSearch: authenticated request
    MeiliSearch-->>HTTP: enqueued task response
    HTTP-->>Index: EnqueuedTaskPromise
    Index-->>Client: return promise
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop to compact, neat and bright,
One tiny call makes indexes right.
Keys and hosts all take their test,
A little task, a tidy nest.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the new compact() API for index compaction.
Linked Issues check ✅ Passed The PR adds the compact endpoint method, matching tests, and the required code sample for issue #2066.
Out of Scope Changes check ✅ Passed The changes stay within the compact API scope and do not introduce unrelated functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mixelburg

Copy link
Copy Markdown
Contributor Author

Closing due to inactivity. Over 3 months with no review. Happy to reopen if the team is interested.

@mixelburg mixelburg closed this Jun 25, 2026
@Strift Strift added the enhancement New feature or request label Jun 30, 2026
@Strift

Strift commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Apologies for the delay; this slipped through the cracks!

@Strift Strift reopened this Jun 30, 2026

@Strift Strift left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR, but the CI is not passing. I suggest running linter + formatter + tests locally before requesting another review 🙏

@Strift
Strift marked this pull request as draft July 6, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.23] Add support for compacting database indexes

2 participants