Skip to main content
When you add, update, or delete documents, Meilisearch’s internal data structures may retain unused space from previous versions of the data. Compaction reclaims this space by reorganizing the index on disk.
Meilisearch Cloud monitors database fragmentation and compacts indexes automatically as needed. Self-hosted users do not benefit from automatic compaction and may need to build a pipeline that periodically compacts indexes to avoid performance degradation.

When to compact

  • After bulk deletions: Removing a large number of documents leaves gaps in the internal storage.
  • After many updates: Repeatedly updating the same documents accumulates obsolete data.
  • When disk usage seems high: If an index uses more disk space than expected for its document count, compaction can help.
You do not need to compact after every operation. It is most useful after large batch changes.

Estimating fragmentation

Fragmentation is directly related to the number of indexing operations Meilisearch performs. Common indexing operations include adding and updating documents, as well as changes to index settings. To estimate your index’s fragmentation, query the /stats route and compare databaseSize to usedDatabaseSize:
  • If the ratio between databaseSize and usedDatabaseSize is bigger than 30%, compacting your indexes may improve performance.
  • If you update documents in your indexes a few times per day, checking fragmentation and compacting your database once per week is a reasonable baseline.
Tune this cadence based on your own indexing patterns: higher write volumes warrant more frequent compaction, while mostly read-only indexes rarely need it.

Compact an index

Send a POST request to /indexes/{index_uid}/compact:
curl \
  -X POST 'MEILISEARCH_URL/indexes/movies/compact' \
  -H 'Authorization: Bearer MEILISEARCH_KEY'
Meilisearch returns a summarized task object:
{
  "taskUid": 87,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "indexCompaction",
  "enqueuedAt": "2025-01-01T00:00:00.000000Z"
}

Monitor the compaction task

Compaction runs asynchronously. Check its progress with the task endpoint:
curl \
  -X GET 'MEILISEARCH_URL/tasks/87' \
  -H 'Authorization: Bearer MEILISEARCH_KEY'

Disk space requirements

Compaction requires temporary disk space roughly equal to the size of the index being compacted. Ensure your machine has sufficient free space before starting. If the disk fills up during compaction, the task fails and the index remains in its pre-compaction state.

Search availability during compaction

Compaction does not block search. Your index remains fully searchable while the operation runs. New indexing tasks will be queued and processed after compaction completes.

Next steps

Compact API reference

Full API reference for the compact endpoint

Monitor tasks

Track the status of asynchronous operations

Indexing best practices

Optimize your indexing workflow for production