From 64bf93b704e3d9751d508cb372d0b33adac71533 Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Tue, 14 Oct 2025 17:21:03 +0200 Subject: [PATCH 1/4] add compact route --- .code-samples.meilisearch.yaml | 4 +++- reference/api/compact.mdx | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 reference/api/compact.mdx diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 721c563f7..95fe1afba 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -1518,7 +1518,9 @@ rename_an_index_1: |- -X PATCH 'MEILISEARCH_URL/indexes/INDEX_A' \ -H 'Content-Type: application/json' \ --data-binary '{ "uid": "INDEX_B" }' - +compact_index_1: |- + curl \ + -X POST 'MEILISEARCH_URL/indexes/INDEX_UID/compact' ### Code samples for experimental features experimental_get_metrics_1: |- diff --git a/reference/api/compact.mdx b/reference/api/compact.mdx new file mode 100644 index 000000000..ab027b86a --- /dev/null +++ b/reference/api/compact.mdx @@ -0,0 +1,36 @@ +--- +title: Compact +description: Use the `/compact` route to reduce database fragmentation. +--- + +import { RouteHighlighter } from '/snippets/route_highlighter.mdx' + +import CodeSamplesCompactIndex1 from '/snippets/samples/code_samples_compact_index_1.mdx'; + +Index fragmentation occurs naturally as you use Meilisearch and can lead to decreased performance over time. `/compact` reorganizes the database and prunes unused space, which may lead to improved indexing and search speeds. + + +To obtain a rough estimate of your index's fragmentation, query the `/stats` route and compute the ratio between `databaseSize` and `usedDatabaseSize`. If the ratio is >= X.Y, compacting your indexes may improve performance. + + +## Compact database + + + +Compact the specified index. + +### Example + + + +#### Response: `202 Accepted` + +```json +{ + "taskUid": 1, + "indexUid": "INDEX_NAME", + "status": "enqueued", + "type": "IndexCompaction", + "enqueuedAt": "2025-01-01T00:00:00.000000Z" +} +``` From e570bfd8393d0bf94b6d1a885eb7fe0286088def Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Wed, 15 Oct 2025 17:21:22 +0200 Subject: [PATCH 2/4] add link to menu, include usage guidelines --- docs.json | 3 ++- reference/api/compact.mdx | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs.json b/docs.json index 9d643be49..2ef97cd44 100644 --- a/docs.json +++ b/docs.json @@ -360,7 +360,8 @@ "reference/api/metrics", "reference/api/logs", "reference/api/export", - "reference/api/webhooks" + "reference/api/webhooks", + "reference/api/compact" ] }, { diff --git a/reference/api/compact.mdx b/reference/api/compact.mdx index ab027b86a..014c5f802 100644 --- a/reference/api/compact.mdx +++ b/reference/api/compact.mdx @@ -9,8 +9,14 @@ import CodeSamplesCompactIndex1 from '/snippets/samples/code_samples_compact_ind Index fragmentation occurs naturally as you use Meilisearch and can lead to decreased performance over time. `/compact` reorganizes the database and prunes unused space, which may lead to improved indexing and search speeds. +Meilisearch Cloud monitors database fragmentation and compacts indexes as needed. Self-hosted users may have to build a pipeline to periodically indexes and fix performance degradation. + -To obtain a rough estimate of your index's fragmentation, query the `/stats` route and compute the ratio between `databaseSize` and `usedDatabaseSize`. If the ratio is >= X.Y, compacting your indexes may improve performance. +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. 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, you may benefit from checking fragmentation and compacting your database once per week. If indexing load is very high, compacting indexes multiple times per week may be necessary to ensure optimal performance. ## Compact database From 5383705b86c7de4429c6b5a5313954eb3eeb727e Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Thu, 16 Oct 2025 14:31:47 +0200 Subject: [PATCH 3/4] Update reference/api/compact.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Renault --- reference/api/compact.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/api/compact.mdx b/reference/api/compact.mdx index 014c5f802..3745b05ea 100644 --- a/reference/api/compact.mdx +++ b/reference/api/compact.mdx @@ -9,7 +9,7 @@ import CodeSamplesCompactIndex1 from '/snippets/samples/code_samples_compact_ind Index fragmentation occurs naturally as you use Meilisearch and can lead to decreased performance over time. `/compact` reorganizes the database and prunes unused space, which may lead to improved indexing and search speeds. -Meilisearch Cloud monitors database fragmentation and compacts indexes as needed. Self-hosted users may have to build a pipeline to periodically indexes and fix performance degradation. +Meilisearch Cloud monitors database fragmentation and compacts indexes as needed. Self-hosted users may have to build a pipeline to periodically compact indexes and fix performance degradation. 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. From 8883a73d7ebb57af7952391d6e1c555a6724e600 Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Thu, 16 Oct 2025 15:11:01 +0200 Subject: [PATCH 4/4] clarify that compaction requires significant amounts of disk space --- reference/api/compact.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reference/api/compact.mdx b/reference/api/compact.mdx index 3745b05ea..a2fad54ee 100644 --- a/reference/api/compact.mdx +++ b/reference/api/compact.mdx @@ -25,6 +25,8 @@ If you update documents in your indexes a few times per day, you may benefit fro Compact the specified index. +During compaction, Meilisearch must temporarily duplicate the database. Ensure you have at least twice the current size of your database in free disk space when compacting an index. + ### Example