Skip to content

add export module for the /export route#763

Open
aznszn wants to merge 1 commit into
meilisearch:mainfrom
aznszn:feat/add-export-route
Open

add export module for the /export route#763
aznszn wants to merge 1 commit into
meilisearch:mainfrom
aznszn:feat/add-export-route

Conversation

@aznszn
Copy link
Copy Markdown
Contributor

@aznszn aznszn commented Feb 2, 2026

Pull Request

Related issue

closes #758

What does this PR do?

  • Added export module
  • Added ExportQuery struct to represent /export route requests
  • Added ExportQueryIndexOptions to represent the indexes field in export request body
  • Added meilisearch_export service in Docker to represent a server being exported to
  • Added ability to request ExportClient (which is a wrapper for a Client configured to connect to the meilisearch_export service) in the meilisearch_test macro
  • Added tests

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
    AI was not used to generate code, tests, or docs. I did use Claude for debugging though
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Summary by CodeRabbit

  • New Features
    • Added data export functionality allowing users to export data between Meilisearch instances with configurable options including payload size and per-index filters.
    • Added infrastructure support for export operations with dedicated services and configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 2, 2026

Warning

Rate limit exceeded

@aznszn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This pull request implements the /export API for the Meilisearch SDK. A new ExportQuery builder enables users to configure and execute export operations between Meilisearch instances. Integration includes task type support and Docker services for local testing.

Changes

Cohort / File(s) Summary
API Implementation
src/export.rs, src/lib.rs
Introduces ExportQuery<'a, Http> struct with builder methods (with_payload_size, with_indexes) and execute() for posting to the /export endpoint. Includes ExportQueryIndexOptions for per-index configuration, comprehensive documentation, and test scaffolding.
Task Integration
src/tasks.rs
Adds Export task variant to TaskType enum with optional details field and corresponding Export struct with camelCase serialization.
Infrastructure
docker-compose.yml
Adds meilisearch and meilisearch_export services (enterprise image, port 7700, master key configuration) and updates package service with export URL environment variable and service dependencies.

Sequence Diagram

sequenceDiagram
    participant User
    participant SDK as SDK Client
    participant HTTP as HTTP Client
    participant ExportSvc as Export Service
    participant TargetMS as Target Meilisearch

    User->>SDK: ExportQuery::new()
    User->>SDK: with_payload_size("50MiB")
    User->>SDK: with_indexes(...)
    User->>SDK: execute()
    
    SDK->>HTTP: POST /export with config
    HTTP->>ExportSvc: Export request (serialized payload)
    ExportSvc->>TargetMS: Connect & initiate export
    TargetMS-->>ExportSvc: Export progress
    ExportSvc-->>HTTP: TaskInfo response
    HTTP-->>SDK: TaskInfo result
    SDK-->>User: Result<TaskInfo, Error>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hops with glee at exports anew!
Builder patterns crafted with care,
Data flows between Meilisearch through,
Tasks tracked in the air.
The SDK grows strong and fair!

🚥 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 accurately describes the main change: adding an export module for the /export route, which is the primary focus of this pull request.
Linked Issues check ✅ Passed The PR implements all requirements from issue #758: ExportQuery struct with builder pattern, support for target URL, API key, payload size, and index selection options, plus integration with Docker compose for testing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the /export API: new export module, ExportQuery structs, TaskType update, and Docker compose setup for testing. No unrelated modifications present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/export.rs`:
- Around line 195-207: The execute method of the export request currently
expects a 200 status; update the HTTP status check in the request invocation
inside Export::execute (the call to self.client.http_client.request with
Method::Post { query: (), body: self }) to expect 202 instead of 200 so the POST
/export async task response is accepted; ensure only the numeric status code is
changed from 200 to 202 to match other async endpoints.
🧹 Nitpick comments (4)
meilisearch-test-macro/src/lib.rs (3)

64-66: Update error message to include ExportClient.

The error message lists valid parameter types but doesn't include the newly added ExportClient.

Suggested fix
                     // TODO: throw this error while pointing to the specific token
                     ty => panic!(
-                        "#[meilisearch_test] can only receive Client, Index or String as parameters but received {ty:?}"
+                        "#[meilisearch_test] can only receive Client, ExportClient, Index or String as parameters but received {ty:?}"
                     ),

70-72: Update error message to include ExportClient.

Same issue here - the error message should include ExportClient as a valid parameter type.

Suggested fix
                 // TODO: throw this error while pointing to the specific token
                 // Used `self` as a parameter
                 FnArg::Receiver(_) => panic!(
-                    "#[meilisearch_test] can only receive Client, Index or String as parameters"
+                    "#[meilisearch_test] can only receive Client, ExportClient, Index or String as parameters"
                 ),

104-114: Potential variable shadowing when both Client and ExportClient are requested.

When a test uses both Client and ExportClient parameters, meilisearch_api_key is declared twice (lines 97 and 109), which causes shadowing. While Rust allows this and it works correctly in this case (both use the same env var), it may trigger compiler warnings or be confusing.

Consider reusing the existing variable or using a distinct name.

Option 1: Conditionally declare api_key only if not already declared
         if use_export_client {
             outer_block.push(parse_quote!(
                 let meilisearch_export_url = option_env!("MEILISEARCH_EXPORT_URL").unwrap_or("http://localhost:7700");
             ));
+            // Only declare meilisearch_api_key if use_client is false (to avoid shadowing)
+        }
+        if use_export_client && !use_client {
             outer_block.push(parse_quote!(
                 let meilisearch_api_key = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
             ));
+        }
+        if use_export_client {
             outer_block.push(parse_quote!(
                 let export_client = ExportClient(Client::new(meilisearch_export_url, Some(meilisearch_api_key)).unwrap());
             ));
         }
src/export.rs (1)

46-56: Consider adding skip_serializing_if for payload_size.

The indexes field has #[serde(skip_serializing_if = "Option::is_none")] but payload_size doesn't. This means null will be serialized when payload_size is None. While this may be acceptable, it's inconsistent with the indexes field handling.

Suggested fix for consistency
 #[derive(Debug, Serialize, Clone)]
 #[serde(rename_all = "camelCase")]
 pub struct ExportQuery<'a, Http: HttpClient> {
     #[serde(skip_serializing)]
     pub client: &'a Client<Http>,
     pub url: String,
     pub api_key: String,
+    #[serde(skip_serializing_if = "Option::is_none")]
     pub payload_size: Option<String>,
     #[serde(skip_serializing_if = "Option::is_none")]
     pub indexes: Option<HashMap<String, ExportQueryIndexOptions>>,
 }

Comment thread src/export.rs
@aznszn aznszn force-pushed the feat/add-export-route branch from 01d135e to b817170 Compare February 2, 2026 11:06
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/export.rs`:
- Around line 18-22: Doc examples in src/export.rs incorrectly read the export
server URL from MEILISEARCH_URL instead of MEILISEARCH_EXPORT_URL; update the
doc comment blocks that define the example env vars so the export URL variable
uses MEILISEARCH_EXPORT_URL (and keep MEILISEARCH_EXPORT_API_KEY mapped
appropriately to MEILISEARCH_API_KEY) in both places where the examples appear
so the docs consistently reference the export-specific env var.
🧹 Nitpick comments (2)
meilisearch-test-macro/src/lib.rs (1)

104-113: Allow an export-specific API key env var fallback.

Using only MEILISEARCH_API_KEY prevents tests against a target with a different key.

♻️ Suggested tweak
-            outer_block.push(parse_quote!(
-                let meilisearch_export_api_key = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
-            ));
+            outer_block.push(parse_quote!(
+                let meilisearch_export_api_key = option_env!("MEILISEARCH_EXPORT_API_KEY")
+                    .or(option_env!("MEILISEARCH_API_KEY"))
+                    .unwrap_or("masterKey");
+            ));
docker-compose.yml (1)

29-43: Pin the Meilisearch enterprise image tag for reproducible runs.

The latest tag can cause unexpected breaking changes in CI. The current stable version is v1.35.0.

♻️ Suggested fix
-    image: getmeili/meilisearch-enterprise:latest
+    image: getmeili/meilisearch-enterprise:${MEILISEARCH_IMAGE_TAG:-v1.35.0}

Apply to both the meilisearch and meilisearch_export services.

Comment thread src/export.rs Outdated
@aznszn aznszn force-pushed the feat/add-export-route branch from b817170 to 3024fd3 Compare February 2, 2026 11:20
@aznszn aznszn marked this pull request as draft February 3, 2026 10:31
@aznszn aznszn force-pushed the feat/add-export-route branch from 3024fd3 to 8358863 Compare February 3, 2026 10:40
@aznszn aznszn marked this pull request as ready for review February 3, 2026 10:41
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/export.rs`:
- Around line 171-172: Update the documentation example to use the
export-specific env var name: replace option_env!("MEILISEARCH_API_KEY") with
option_env!("MEILISEARCH_EXPORT_API_KEY") in the doc comment so the example
aligns with other examples that use MEILISEARCH_EXPORT_API_KEY.
🧹 Nitpick comments (1)
docker-compose.yml (1)

29-43: Pin the Meilisearch image tags instead of latest for repeatable builds.

Replace getmeili/meilisearch-enterprise:latest with a specific version tag (e.g., v1.32.1) in both services. The latest tag can cause non-deterministic CI runs when new releases are published.

Comment thread src/export.rs Outdated
@aznszn aznszn force-pushed the feat/add-export-route branch from 8358863 to 152cb76 Compare February 3, 2026 10:52
@aznszn
Copy link
Copy Markdown
Contributor Author

aznszn commented Mar 6, 2026

@curquiza could you have a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the /export api

1 participant