Skip to content

Commit 00686cf

Browse files
Add /compact route (#3382)
--------- Co-authored-by: Clément Renault <[email protected]>
1 parent 1c03b55 commit 00686cf

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.code-samples.meilisearch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,9 @@ rename_an_index_1: |-
15181518
-X PATCH 'MEILISEARCH_URL/indexes/INDEX_A' \
15191519
-H 'Content-Type: application/json' \
15201520
--data-binary '{ "uid": "INDEX_B" }'
1521-
1521+
compact_index_1: |-
1522+
curl \
1523+
-X POST 'MEILISEARCH_URL/indexes/INDEX_UID/compact'
15221524
15231525
### Code samples for experimental features
15241526
experimental_get_metrics_1: |-

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@
360360
"reference/api/metrics",
361361
"reference/api/logs",
362362
"reference/api/export",
363-
"reference/api/webhooks"
363+
"reference/api/webhooks",
364+
"reference/api/compact"
364365
]
365366
},
366367
{

reference/api/compact.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Compact
3+
description: Use the `/compact` route to reduce database fragmentation.
4+
---
5+
6+
import { RouteHighlighter } from '/snippets/route_highlighter.mdx'
7+
8+
import CodeSamplesCompactIndex1 from '/snippets/samples/code_samples_compact_index_1.mdx';
9+
10+
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.
11+
12+
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.
13+
14+
<Tip>
15+
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.
16+
17+
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.
18+
19+
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.
20+
</Tip>
21+
22+
## Compact database
23+
24+
<RouteHighlighter method="POST" path="/indexes/{index_uid}/compact" />
25+
26+
Compact the specified index.
27+
28+
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.
29+
30+
### Example
31+
32+
<CodeSamplesCompactIndex1 />
33+
34+
#### Response: `202 Accepted`
35+
36+
```json
37+
{
38+
"taskUid": 1,
39+
"indexUid": "INDEX_NAME",
40+
"status": "enqueued",
41+
"type": "IndexCompaction",
42+
"enqueuedAt": "2025-01-01T00:00:00.000000Z"
43+
}
44+
```

0 commit comments

Comments
 (0)