Skip to content

Add support for export API #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ernestorbemx
Copy link

@ernestorbemx ernestorbemx commented Aug 8, 2025

Pull Request

Related issue

Fixes #877

What does this PR do?

  • Implement Export API
  • The implementation is based on some other APIS like Dumps API
  • Integration tests for new Client#export method
  • Unit tests for newly created ExportRequest and ExportIndexFilter classes

PR checklist

Please check if your PR fulfills the following requirements:

  • 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?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features
    • Added support for exporting documents between Meilisearch instances.
    • Introduced options to filter exported indexes and customize export requests.
  • Tests
    • Added integration and unit tests to validate export functionality and export request handling.
  • Documentation
    • Provided a new code sample demonstrating how to initiate an export request.

Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

A new export feature for the Meilisearch Java SDK has been implemented. This includes adding the ExportRequest and ExportIndexFilter classes, a public export method to the Client class, integration and unit tests for export functionality, and an example code sample in .code-samples.meilisearch.yaml.

Changes

Cohort / File(s) Change Summary
Export Feature: Core Implementation
src/main/java/com/meilisearch/sdk/Client.java, src/main/java/com/meilisearch/sdk/ExportRequest.java, src/main/java/com/meilisearch/sdk/ExportIndexFilter.java
Added export method to Client, and introduced ExportRequest and ExportIndexFilter classes with builder patterns and JSON serialization.
Export Feature: Integration and Unit Tests
src/test/java/com/meilisearch/integration/ClientTest.java, src/test/java/com/meilisearch/sdk/ExportRequestTest.java
Added integration test for export workflow and unit tests for ExportRequest and ExportIndexFilter logic, including JSON output and getter validation.
Documentation: Example Code
.code-samples.meilisearch.yaml
Added a new code sample under export_post_1 demonstrating export usage.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant MeilisearchServer

    User->>Client: Build ExportRequest
    User->>Client: Call export(request)
    Client->>MeilisearchServer: POST /export (with ExportRequest JSON)
    MeilisearchServer-->>Client: TaskInfo (export task enqueued)
    Client-->>User: Return TaskInfo
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Assessment against linked issues

Objective Addressed Explanation
Add the new methods to interact with the Meilisearch API (#877)
Add new tests cases (#877)
Write an example code in .code-samples.meilisearch.yaml under the export_post_1 key (#877)

Poem

A rabbit hops through code so bright,
Exporting data left and right!
With filters, requests, and tests in tow,
The Meilisearch SDK’s ready to go.
Now tasks are queued, the docs are neat—
This export feature is quite a treat!
🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0926b22 and 6778982.

📒 Files selected for processing (4)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/main/java/com/meilisearch/sdk/Client.java (1 hunks)
  • src/main/java/com/meilisearch/sdk/ExportIndexFilter.java (1 hunks)
  • src/test/java/com/meilisearch/integration/ClientTest.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • .code-samples.meilisearch.yaml
  • src/main/java/com/meilisearch/sdk/Client.java
  • src/test/java/com/meilisearch/integration/ClientTest.java
  • src/main/java/com/meilisearch/sdk/ExportIndexFilter.java
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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

🔭 Outside diff range comments (1)
.code-samples.meilisearch.yaml (1)

846-849: Fix builder usage: Lombok builders don't use setXxx(...).

ExportRequest.builder().setUrl(...) won’t compile. Lombok’s builder uses the field name as the setter, i.e. url(...).

Apply this diff:

-export_post_1: |-
-  ExportRequest request = ExportRequest.builder().setUrl("http://anothermeiliinstance:7070").build();
-  client.export(request);
+export_post_1: |-
+  ExportRequest request = ExportRequest.builder().url("http://anothermeiliinstance:7070").build();
+  client.export(request);
🧹 Nitpick comments (11)
src/main/java/com/meilisearch/sdk/Client.java (1)

221-231: Add input validation and fix minor Javadoc casing.

  • Validate request and request.url early to fail fast on misuse.
  • Javadoc: “Instances” -> “instances”.

Apply this diff:

-    /**
-     * Triggers the export of documents between Meilisearch Instances.
+    /**
+     * Triggers the export of documents between Meilisearch instances.
      *
      * @param request Export request parameters
      * @return Meilisearch API response as TaskInfo
      * @throws MeilisearchException if an error occurs
      * @see <a href="https://www.meilisearch.com/docs/reference/api/export">API specification</a>
      */
     public TaskInfo export(ExportRequest request) throws MeilisearchException {
-        return config.httpClient.post("/export", request, TaskInfo.class);
+        if (request == null) {
+            throw new IllegalArgumentException("ExportRequest must not be null");
+        }
+        if (request.getUrl() == null || request.getUrl().isEmpty()) {
+            throw new IllegalArgumentException("ExportRequest.url must not be null or empty");
+        }
+        return config.httpClient.post("/export", request, TaskInfo.class);
     }
src/test/java/com/meilisearch/integration/ClientTest.java (1)

325-329: Rename local variable for clarity.

Rename snapshot to exportTask to avoid confusion with snapshot tests.

-        Task snapshot = client.getTask(task.getTaskUid());
+        Task exportTask = client.getTask(task.getTaskUid());
 
-        assertThat(task.getStatus(), is(equalTo(TaskStatus.ENQUEUED)));
-        assertThat(snapshot.getType(), is(equalTo("export")));
+        assertThat(task.getStatus(), is(equalTo(TaskStatus.ENQUEUED)));
+        assertThat(exportTask.getType(), is(equalTo("export")));
src/main/java/com/meilisearch/sdk/ExportIndexFilter.java (2)

15-19: Fix Javadoc class name.

This Javadoc refers to ExportRequest; it should reference ExportIndexFilter.

-    /**
-     * Method that returns the JSON String of the ExportRequest
+    /**
+     * Method that returns the JSON String of the ExportIndexFilter
      *
-     * @return JSON String of the ExportRequest query
+     * @return JSON String of the ExportIndexFilter
      */

22-27: Only include overrideSettings when true (avoid noisy JSON).

The current code always emits "overrideSettings": false. Emit it only when true for cleaner payloads.

-        JSONObject jsonObject =
-                new JSONObject()
-                        .putOpt("filter", this.filter)
-                        .putOpt("overrideSettings", this.overrideSettings);
+        JSONObject jsonObject = new JSONObject();
+        if (this.filter != null) {
+            jsonObject.put("filter", this.filter);
+        }
+        if (this.overrideSettings) {
+            jsonObject.put("overrideSettings", true);
+        }
         return jsonObject.toString();
src/test/java/com/meilisearch/sdk/ExportRequestTest.java (7)

18-22: Avoid brittle JSON string equality; assert structure via JSONObject

Comparing the raw JSON string ties the test to key ordering. Parse and assert fields instead.

-        String expected = "{\"overrideSettings\":false}";
-        assertThat(filter.toString(), is(equalTo(expected)));
+        JSONObject json = new JSONObject(filter.toString());
+        assertThat(json.getBoolean("overrideSettings"), is(false));
+        assertThat(json.has("filter"), is(false));
         assertThat(filter.getFilter(), is(nullValue()));
         assertThat(filter.isOverrideSettings(), is(false));

27-30: Make filter serialization check order-agnostic

Same concern: compare JSON structurally to avoid depending on key order.

-        String expected = "{\"overrideSettings\":true}";
-        assertThat(filter.toString(), is(equalTo(expected)));
+        JSONObject json = new JSONObject(filter.toString());
+        assertThat(json.getBoolean("overrideSettings"), is(true));
+        assertThat(json.has("filter"), is(false));
         assertThat(filter.isOverrideSettings(), is(true));

35-38: Assert JSON fields instead of exact string

Order of "filter" and "overrideSettings" should not matter; assert keys/values.

-        String expected = "{\"filter\":\"status = 'active'\",\"overrideSettings\":false}";
-        assertThat(filter.toString(), is(equalTo(expected)));
+        JSONObject json = new JSONObject(filter.toString());
+        assertThat(json.getString("filter"), is(equalTo("status = 'active'")));
+        assertThat(json.getBoolean("overrideSettings"), is(false));
         assertThat(filter.getFilter(), is(equalTo("status = 'active'")));

63-69: Replace JSON string equality with structural comparison

JSONObject.toString() can reorder keys. Use JSONObject#similar for semantic equality.

-        assertThat(expectedJson.toString(), is(json.toString()));
+        assertThat(json.similar(expectedJson), is(true));

70-77: Optional: assert absence rather than null for nested 'filter'

If the intended wire format omits nulls, assert absence to catch accidental inclusion of "filter": null.

-        assertThat(starIndex.isNull("filter"), is(true));
+        assertThat(starIndex.has("filter"), is(false));

If nulls are acceptable/desirable in payloads, keep the current check. Please confirm the expected API contract.


13-16: Clarify parity between toString() and HTTP serialization

Most tests validate toString()-produced JSON. Ensure the HTTP client uses the same serialization (key naming, null handling) to avoid divergences between unit tests and actual requests. If a different serializer (e.g., Gson/Jackson) is used, consider adding a serializer-focused test or aligning toString with it.

I can add a test that serializes via the actual HTTP layer to validate the final payload if desired.


45-47: Minor Hamcrest style nit (optional)

You can drop either is() or equalTo() for brevity without losing clarity: assertThat(x, is(y)) or assertThat(x, equalTo(y)).

Also applies to: 70-73, 95-97

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34e6053 and 0926b22.

📒 Files selected for processing (6)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/main/java/com/meilisearch/sdk/Client.java (1 hunks)
  • src/main/java/com/meilisearch/sdk/ExportIndexFilter.java (1 hunks)
  • src/main/java/com/meilisearch/sdk/ExportRequest.java (1 hunks)
  • src/test/java/com/meilisearch/integration/ClientTest.java (2 hunks)
  • src/test/java/com/meilisearch/sdk/ExportRequestTest.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/com/meilisearch/sdk/ExportIndexFilter.java (1)
src/main/java/com/meilisearch/sdk/ExportRequest.java (1)
  • Builder (7-33)
src/main/java/com/meilisearch/sdk/ExportRequest.java (1)
src/main/java/com/meilisearch/sdk/ExportIndexFilter.java (1)
  • Builder (6-28)
🔇 Additional comments (3)
src/main/java/com/meilisearch/sdk/Client.java (1)

229-231: API wiring looks correct.

The endpoint, payload type, and return type are consistent with other Client methods.

src/main/java/com/meilisearch/sdk/ExportRequest.java (1)

13-16: Fields conform to Meilisearch v1.16 Export API spec

All request‐body fields match the official spec for Meilisearch v1.16:

• src/main/java/com/meilisearch/sdk/ExportRequest.java
– url: String (required)
– apiKey: String (optional, accepts null)
– payloadSize: String (optional, human-readable with unit)
– indexes: Map<String,ExportIndexFilter> (optional)

• src/main/java/com/meilisearch/sdk/ExportIndexFilter.java
– filter: String (optional, null allowed)
– overrideSettings: boolean (optional, defaults to false)

No changes are needed.

src/test/java/com/meilisearch/sdk/ExportRequestTest.java (1)

44-49: Good: robust null checks for optional fields

Using JSONObject.isNull handles both absent and explicit null cases for apiKey/indexes. This keeps tests resilient across serializer strategies.

Comment on lines +25 to +31
JSONObject jsonObject =
new JSONObject()
.put("url", this.url)
.putOpt("apiKey", this.apiKey)
.putOpt("payloadSize", this.payloadSize)
.putOpt("indexes", this.indexes);
return jsonObject.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Do not expose secrets in toString(); redact apiKey.

toString() is frequently logged. Emitting a raw API key is a security risk.

Apply this diff to redact the key:

-        JSONObject jsonObject =
-                new JSONObject()
-                        .put("url", this.url)
-                        .putOpt("apiKey", this.apiKey)
-                        .putOpt("payloadSize", this.payloadSize)
-                        .putOpt("indexes", this.indexes);
+        String redactedApiKey = (this.apiKey == null) ? null : "REDACTED";
+        JSONObject jsonObject =
+                new JSONObject()
+                        .put("url", this.url)
+                        .putOpt("apiKey", redactedApiKey)
+                        .putOpt("payloadSize", this.payloadSize)
+                        .putOpt("indexes", this.indexes);
         return jsonObject.toString();

If you need an unredacted JSON string for tests, consider adding a dedicated method like toJson(boolean redactSecrets) and update tests accordingly. I can draft that change and the test updates if you want.

🤖 Prompt for AI Agents
In src/main/java/com/meilisearch/sdk/ExportRequest.java around lines 25 to 31,
the toString() method currently includes the raw apiKey, which is a security
risk. Modify the method to redact the apiKey value by replacing it with a
placeholder like "REDACTED" before returning the JSON string. Alternatively,
create a new method such as toJson(boolean redactSecrets) that conditionally
redacts the apiKey, and update tests to use this method accordingly.

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.

[v1.16] Add support for /export API
1 participant