Skip to content

Conversation

@yamiSukehiro2907
Copy link

@yamiSukehiro2907 yamiSukehiro2907 commented Nov 18, 2025

Fixes #888


🚀 Meilisearch Java SDK – Support for Meilisearch 1.18

What does this PR do?

This PR adds full support for Meilisearch 1.18 features in the Java SDK.
It implements:


1. queryVector support in search responses

  • When a search request includes retrieveVectors=true, Meilisearch now returns a new queryVector field.
  • The SDK has been updated to deserialize this field inside SearchResult.
  • Users can now access it via getQueryVector().
  • Added a new test:
    • SearchResultQueryVectorTest

2. Index renaming using PATCH /indexes/:uid

  • Updated IndexesHandler.updateIndex() to accept a new indexUid parameter for renaming.
  • Example request supported:
{ "indexUid": "indexB" }
  • Added test:

    • IndexRenameTest

3. Index renaming using swap-indexes

  • Updated SwapIndexesParams to include rename.
  • Updated IndexesHandler.swapIndexes() to send the rename flag.
  • Supports usage like:
[
  {
    "indexes": ["indexA", "indexB"],
    "rename": true
  }
]
  • Added test:

    • SwapIndexRenameTest

4. Code sample update

  • Added a new example under the rename_an_index_1 key in
    .code-samples.meilisearch.yaml
  • The example matches the official CURL snippet for renaming via index update.

Summary of changes

Source

  • SearchResult.java
  • IndexesHandler.java
  • SwapIndexesParams.java
  • Index.java (if updated method exposed)

Tests

  • SearchResultQueryVectorTest.java
  • IndexRenameTest.java
  • SwapIndexRenameTest.java

Documentation

  • .code-samples.meilisearch.yaml

PR Checklist

  • Implements all Meilisearch 1.18 features required by the issue
  • Tests added for all new behavior
  • All tests pass (./gradlew clean build)
  • Formatting applied (spotlessApply)
  • Descriptive and accurate PR title
  • No breaking changes introduced

Summary by CodeRabbit

  • New Features

    • Index renaming: rename indexes via the updateIndex API for easier index management
    • Query vectors in search results: search responses now include query-vector data
    • Swap indexes: swap operation supports a rename option for more flexible workflows
  • Chores

    • Build and tooling: Gradle task registration and minor build config refinements
  • Tests

    • Added tests covering index rename, swap-with-rename, and query-vector parsing

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2025

Walkthrough

Adds support for Meilisearch 1.18 features: introduces a queryVector field in search responses, enables index renaming via a new updateIndex(uid, primaryKey, indexUid) route and IndexesHandler.updateIndexUid, adds rename to swap params, includes tests and a code sample, and updates Gradle task registration and encoding.

Changes

Cohort / File(s) Summary
Search Response Models
src/main/java/com/meilisearch/sdk/model/SearchResult.java, src/main/java/com/meilisearch/sdk/model/SearchResultPaginated.java
Added queryVector field (ArrayList<Float>) to capture query vectors in search responses.
Index Management API
src/main/java/com/meilisearch/sdk/Client.java, src/main/java/com/meilisearch/sdk/IndexesHandler.java
Made IndexesHandler public; added updateIndexUid(String uid, String indexUid); added overloaded Client.updateIndex(String uid, String primaryKey, String indexUid) which routes to updateIndexUid when indexUid is non-null.
Index Swap Parameters
src/main/java/com/meilisearch/sdk/model/SwapIndexesParams.java
Added protected Boolean rename field to allow rename behavior during swap-indexes calls.
Tests
src/test/java/com/meilisearch/sdk/IndexRenameTest.java, src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java, src/test/java/com/meilisearch/sdk/SwapIndexRenameTest.java
Added tests verifying index rename via PATCH, presence and values of queryVector in search responses, and rename flag in swap-indexes payload.
Code Samples & Build Config
.code-samples.meilisearch.yaml, build.gradle
Added rename_an_index_1 code sample demonstrating index renaming; migrated Gradle tasks to tasks.register(...), added UTF-8 encoding for compilation, and minor formatting adjustments.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant IndexesHandler
    participant API
    participant MockServer

    rect rgb(235, 245, 255)
    Note over Client,IndexesHandler: Rename index via updateIndex overload
    Client->>Client: updateIndex("indexA", null, "indexB")
    Client->>IndexesHandler: updateIndexUid("indexA","indexB")
    IndexesHandler->>API: PATCH /indexes/indexA  {"uid":"indexB"}
    API->>MockServer: deliver request
    MockServer-->>API: 202 { "taskUid":123 }
    API-->>IndexesHandler: TaskInfo
    IndexesHandler-->>Client: TaskInfo
    end

    rect rgb(255, 245, 235)
    Note over Client,API: Rename via swap-indexes with rename=true
    Client->>API: POST /swap-indexes  [{"indexes":["A","B"],"rename":true}]
    API->>MockServer: deliver request
    MockServer-->>API: 202 { "taskUid":456 }
    API-->>Client: TaskInfo
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify endpoint path construction to avoid double-slash issues noted in tests (e.g., //indexes/oldIndex).
  • Confirm JSON property name used in updateIndexUid matches server expectation (uid vs indexUid) and serialization behavior.
  • Ensure queryVector deserialization handles floats and absent fields gracefully.
  • Review API surface change: new public class/method signatures.

Suggested reviewers

  • brunoocasali

Poem

🐰 I nudged a uid from A to B with care,
Vectors now hop along queries in the air,
Tests hum like carrots, tasks carry the tune,
Rename and search — a bright new moon! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR contains one out-of-scope change: the build.gradle file was modified to use Gradle's task registration API and add UTF-8 encoding, which is unrelated to Meilisearch 1.18 features. Remove the build.gradle modifications (task registration API updates and encoding changes) as they are not part of the Meilisearch 1.18 feature implementation defined in issue #888.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main changes: adding Meilisearch 1.18 features (queryVector and index renaming) to the Java SDK.
Linked Issues check ✅ Passed All coding requirements from issue #888 are met: queryVector added to SearchResult/SearchResultPaginated, index renaming implemented via updateIndex and swapIndexes, tests added, and code sample added.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 eb7f772 and d0df797.

📒 Files selected for processing (2)
  • src/main/java/com/meilisearch/sdk/IndexesHandler.java (2 hunks)
  • src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1 hunks)
🔇 Additional comments (3)
src/main/java/com/meilisearch/sdk/IndexesHandler.java (2)

124-136: LGTM! The JSON field name has been corrected.

The implementation correctly uses "uid" as the field name in the request body, which matches the Meilisearch API specification for PATCH /indexes/{index_uid}. This addresses the critical issue raised in the previous review where "indexUid" would have been silently ignored by the server.


15-15: ****

The concern about visibility inconsistency is unfounded. Verification shows that all handler classes in the SDK (TasksHandler, KeysHandler, InstanceHandler, SettingsHandler, and the JSON handlers) are already public. IndexesHandler becoming public is consistent with the established pattern across the codebase, not a deviation from it.

Likely an incorrect or invalid review comment.

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

32-51: LGTM! The test now correctly uses the SDK's public API.

The test has been updated to call client.updateIndex() rather than manually constructing HTTP requests, which properly validates the SDK's index rename functionality. The test correctly asserts:

  • The response is parsed into a TaskInfo object
  • The PATCH request is sent to the correct endpoint
  • The request body contains "uid":"newIndex" (matching the corrected field name)
  • Authentication headers are properly included

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
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: 3

🧹 Nitpick comments (5)
src/main/java/com/meilisearch/sdk/model/SearchResultPaginated.java (1)

26-26: Consider adding test coverage for queryVector in paginated results

The queryVector field is consistent with SearchResult and will be exposed via Lombok getters, which is good. To avoid regressions, I’d add a small test that deserializes a paginated search response including queryVector and asserts the values, similar to SearchResultQueryVectorTest.

src/main/java/com/meilisearch/sdk/model/SwapIndexesParams.java (1)

13-13: Document the semantics of the rename flag on swap-indexes params

The rename flag integrates nicely with the existing chained params and will serialize as "rename": true when set. To help users discover it, consider expanding the class-level or method-level docs (and any public docs) to briefly explain that when rename is true, the swap also renames the indexes according to Meilisearch 1.18 semantics.

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

124-136: Index rename handler is correct; consider a small guard for invalid input

updateIndexUid correctly constructs a {"indexUid": "<newUid>"} body and PATCHes /indexes/{uid}, matching the intended rename flow and the pattern used by updatePrimaryKey.

You might optionally add a simple precondition (e.g., reject null/blank indexUid) to fail fast if this method is ever called directly with invalid input, instead of relying solely on the Client overload to guard it.

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

168-175: Overloaded updateIndex works; consider clarifying behavior and API shape

The new overload cleanly routes:

  • to updateIndexUid when indexUid != null (rename), and
  • to updatePrimaryKey otherwise (primary key update),

so behavior is correct and non-breaking for existing callers.

Two optional improvements to consider:

  • Clarify the Javadoc to explicitly describe the precedence (“if indexUid is non-null, the primary key argument is ignored”) so callers don’t assume both can be updated in one call.
  • Long term, a dedicated renameIndex(String uid, String indexUid) entry point could make the API more explicit than a tri-parameter overload that multiplexes two concerns.
src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java (1)

12-31: Consider adding edge case tests.

The test validates the happy path for queryVector deserialization. Consider adding test cases for edge scenarios:

  • queryVector field is absent (should be null or empty)
  • queryVector is null in JSON
  • queryVector is an empty array

This ensures robust handling of various API response formats.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 45861af and a6bf507.

📒 Files selected for processing (11)
  • .code-samples.meilisearch.yaml (1 hunks)
  • data.ms/VERSION (1 hunks)
  • data.ms/instance-uid (1 hunks)
  • src/main/java/com/meilisearch/sdk/Client.java (2 hunks)
  • src/main/java/com/meilisearch/sdk/IndexesHandler.java (1 hunks)
  • src/main/java/com/meilisearch/sdk/model/SearchResult.java (1 hunks)
  • src/main/java/com/meilisearch/sdk/model/SearchResultPaginated.java (1 hunks)
  • src/main/java/com/meilisearch/sdk/model/SwapIndexesParams.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/SwapIndexRenameTest.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java (1)
src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java (1)
  • GsonJsonHandler (12-56)
src/test/java/com/meilisearch/sdk/SwapIndexRenameTest.java (1)
src/main/java/com/meilisearch/sdk/http/CustomOkHttpClient.java (1)
  • CustomOkHttpClient (18-126)
src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1)
src/main/java/com/meilisearch/sdk/http/CustomOkHttpClient.java (1)
  • CustomOkHttpClient (18-126)
🔇 Additional comments (5)
data.ms/VERSION (1)

1-1: Ensure VERSION value stays in sync with published SDK version

1.26.0 looks fine as a data marker, but please double-check it matches the actual SDK version used in packaging (e.g., Maven coordinates, release notes) so tests and metadata don’t drift.

data.ms/instance-uid (1)

1-1: UUID fixture looks fine

Static instance UID value is acceptable as a deterministic fixture; no functional issues from this change.

.code-samples.meilisearch.yaml (1)

857-858: Rename sample correctly targets the new updateIndex overload

The rename_an_index_1 snippet uses client.updateIndex("indexA", null, "indexB");, which cleanly maps to “rename indexA to indexB” while leaving the primary key untouched. This aligns with the new overload semantics and fits well with the surrounding samples.

src/main/java/com/meilisearch/sdk/model/SearchResult.java (1)

21-21: queryVector field addition is consistent and testable

Adding ArrayList<Float> queryVector; alongside existing response fields is consistent with the current model style and should deserialize correctly given the existing JSON mapping and the dedicated test.

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

13-13: Wildcard java.util import is acceptable given multiple usages

Switching to import java.util.*; is harmless here, since the class already depends on several java.util types (Map, HashMap, Date, TimeZone, UUID). No action needed unless your style guide prefers explicit imports.

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: 0

🧹 Nitpick comments (3)
src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1)

62-80: Optional: align second test’s HTTP assertions with the first.

The second test correctly verifies path and payload for different names. For symmetry and slightly stronger coverage, you could also assert the HTTP method and Authorization header as in the first test.

-        RecordedRequest request = mockServer.takeRequest();
-        assertThat(request.getPath(), equalTo("/indexes/oldIndex"));
-
-        String requestBody = request.getBody().readUtf8();
+        RecordedRequest request = mockServer.takeRequest();
+        assertThat(request.getMethod(), equalTo("PATCH"));
+        assertThat(request.getPath(), equalTo("/indexes/oldIndex"));
+        assertThat(request.getHeader("Authorization"), equalTo("Bearer masterKey"));
+
+        String requestBody = request.getBody().readUtf8();
         assertThat(requestBody, containsString("\"indexUid\":\"newIndex\""));
src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java (2)

72-99: Non-rename swap test is good; header assertion is an optional enhancement.

The test correctly covers rename=false, index names, and taskUid. For parity with the first test, you might also assert the Authorization header, but the current coverage is acceptable.

-        RecordedRequest request = mockServer.takeRequest();
-        assertThat(request.getMethod(), equalTo("POST"));
-        assertThat(request.getPath(), equalTo("/swap-indexes"));
-
-        String requestBody = request.getBody().readUtf8();
+        RecordedRequest request = mockServer.takeRequest();
+        assertThat(request.getMethod(), equalTo("POST"));
+        assertThat(request.getPath(), equalTo("/swap-indexes"));
+        assertThat(request.getHeader("Authorization"), equalTo("Bearer masterKey"));
+
+        String requestBody = request.getBody().readUtf8();
         assertThat(requestBody, containsString("\"rename\":false"));

101-132: Consider slightly strengthening multi-pair swap assertions and reducing JSON-shape brittleness.

The multi-pair test correctly verifies both index pairs and that the payload is a JSON array. To make it a bit more robust and explicit you could:

  • Trim the body before startsWith/endsWith so a trailing newline won’t break the test.
  • Optionally assert both "rename":true and "rename":false are present to ensure per-pair flags are serialized.
-        String requestBody = request.getBody().readUtf8();
-
-        assertThat(requestBody, containsString("\"indexA\""));
-        assertThat(requestBody, containsString("\"indexB\""));
-        assertThat(requestBody, containsString("\"indexC\""));
-        assertThat(requestBody, containsString("\"indexD\""));
-        assertThat(requestBody, startsWith("["));
-        assertThat(requestBody, endsWith("]"));
+        String requestBody = request.getBody().readUtf8();
+
+        assertThat(requestBody, containsString("\"indexA\""));
+        assertThat(requestBody, containsString("\"indexB\""));
+        assertThat(requestBody, containsString("\"indexC\""));
+        assertThat(requestBody, containsString("\"indexD\""));
+        assertThat(requestBody, containsString("\"rename\":true"));
+        assertThat(requestBody, containsString("\"rename\":false"));
+
+        String trimmedBody = requestBody.trim();
+        assertThat(trimmedBody, startsWith("["));
+        assertThat(trimmedBody, endsWith("]"));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6bf507 and 2a5ec2f.

📒 Files selected for processing (3)
  • build.gradle (1 hunks)
  • src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • build.gradle
🔇 Additional comments (4)
src/test/java/com/meilisearch/sdk/IndexRenameTest.java (2)

18-38: MockWebServer setup/teardown and Config wiring look correct.

Creating a per-test MockWebServer, trimming the trailing slash from the base URL, and shutting the server down in @AfterEach is clean and consistent; no issues here.


40-60: Rename test cleanly exercises IndexesHandler.updateIndexUid over HTTP.

The test validates:

  • Response mapping via TaskInfo.getTaskUid()
  • HTTP verb (PATCH), path (/indexes/indexA), and Authorization header
  • JSON payload including "indexUid":"indexB"

This gives good coverage of the new rename behavior in the handler.

src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java (2)

19-39: Client + MockWebServer wiring is straightforward and consistent.

Using Config with the trimmed mock base URL and constructing a Client per test, plus proper MockWebServer lifecycle, looks good.


41-70: Swap-with-rename test validates all critical request/response aspects.

You’re asserting:

  • POST /swap-indexes
  • Authorization header
  • JSON body including "rename":true and both index names
  • TaskInfo deserialization via taskUid

This is solid coverage for the new rename=true behavior.

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: 0

🧹 Nitpick comments (4)
src/test/java/com/meilisearch/sdk/IndexRenameTest.java (2)

40-82: Consider consolidating with @ParameterizedTest.

Both test methods have identical structure and differ only in the index names and expected taskUid. Using @ParameterizedTest with @MethodSource or @CsvSource would reduce duplication and make it easier to add more test cases.

Example refactor:

@ParameterizedTest
@CsvSource({
    "indexA, indexB, 123",
    "oldIndex, newIndex, 456"
})
void testRenameIndex(String oldUid, String newUid, int expectedTaskUid) throws Exception {
    String responseJson = String.format(
        "{\"taskUid\":%d,\"indexUid\":\"%s\",\"status\":\"enqueued\",\"type\":\"indexUpdate\",\"enqueuedAt\":\"2024-01-01T00:00:00Z\"}",
        expectedTaskUid, newUid);
    mockServer.enqueue(new MockResponse()
        .setResponseCode(202)
        .setBody(responseJson)
        .addHeader("Content-Type", "application/json"));

    TaskInfo result = handler.updateIndexUid(oldUid, newUid);

    assertThat(result, is(notNullValue()));
    assertThat(result.getTaskUid(), is(equalTo(expectedTaskUid)));

    RecordedRequest request = mockServer.takeRequest();
    assertThat(request.getMethod(), equalTo("PATCH"));
    assertThat(request.getPath(), equalTo("/indexes/" + oldUid));
    assertThat(request.getHeader("Authorization"), equalTo("Bearer masterKey"));

    String requestBody = request.getBody().readUtf8();
    assertThat(requestBody, containsString("\"indexUid\":\"" + newUid + "\""));
}

40-82: Consider adding error case tests.

The tests cover happy path scenarios well but don't verify error handling. Consider adding tests for:

  • 404 response when the source index doesn't exist
  • 400 response for invalid index names
  • 409 response when the target index name already exists
  • Null or empty string handling

Example error case test:

@Test
void testRenameIndexNotFound() throws Exception {
    String errorJson = "{\"message\":\"Index `nonexistent` not found.\",\"code\":\"index_not_found\",\"type\":\"invalid_request\",\"link\":\"https://docs.meilisearch.com/errors#index_not_found\"}";
    mockServer.enqueue(new MockResponse()
        .setResponseCode(404)
        .setBody(errorJson)
        .addHeader("Content-Type", "application/json"));

    // Assert that appropriate exception is thrown
    assertThrows(MeilisearchApiException.class, () -> {
        handler.updateIndexUid("nonexistent", "newName");
    });
}
src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java (2)

41-100: Consider consolidating with @ParameterizedTest.

The first two test methods have nearly identical structure and differ only in the rename flag value and expected taskUid. Using @ParameterizedTest would reduce duplication.

Example refactor:

@ParameterizedTest
@CsvSource({
    "true, indexA, indexB, 789",
    "false, indexC, indexD, 790"
})
void testSwapIndexesWithRenameFlag(boolean rename, String indexA, String indexB, int expectedTaskUid) throws Exception {
    String responseJson = String.format(
        "{\"taskUid\":%d,\"status\":\"enqueued\",\"type\":\"indexSwap\",\"enqueuedAt\":\"2024-01-01T00:00:00Z\"}",
        expectedTaskUid);
    mockServer.enqueue(new MockResponse()
        .setResponseCode(202)
        .setBody(responseJson)
        .addHeader("Content-Type", "application/json"));

    SwapIndexesParams[] params = {
        new SwapIndexesParams()
            .setIndexes(new String[]{indexA, indexB})
            .setRename(rename)
    };

    TaskInfo result = client.swapIndexes(params);

    assertThat(result, is(notNullValue()));
    assertThat(result.getTaskUid(), is(equalTo(expectedTaskUid)));

    RecordedRequest request = mockServer.takeRequest();
    assertThat(request.getMethod(), equalTo("POST"));
    assertThat(request.getPath(), equalTo("/swap-indexes"));

    String requestBody = request.getBody().readUtf8();
    assertThat(requestBody, containsString("\"rename\":" + rename));
    assertThat(requestBody, containsString(indexA));
    assertThat(requestBody, containsString(indexB));
}

41-137: Consider adding error and edge case tests.

The tests cover happy path scenarios effectively but don't verify error handling or edge cases. Consider adding tests for:

  • 404 response when one of the indexes doesn't exist
  • 400 response for invalid payloads (e.g., empty indexes array, single index, mismatched array lengths)
  • Empty SwapIndexesParams[] array
  • Null values in the params

Example edge case test:

@Test
void testSwapIndexesWithEmptyArray() throws Exception {
    SwapIndexesParams[] params = {};
    
    // Verify behavior - should it throw an exception or send empty array?
    // This depends on the API specification
}

@Test
void testSwapIndexesNotFound() throws Exception {
    String errorJson = "{\"message\":\"Index `nonexistent` not found.\",\"code\":\"index_not_found\",\"type\":\"invalid_request\"}";
    mockServer.enqueue(new MockResponse()
        .setResponseCode(404)
        .setBody(errorJson)
        .addHeader("Content-Type", "application/json"));

    SwapIndexesParams[] params = {
        new SwapIndexesParams()
            .setIndexes(new String[]{"nonexistent", "indexB"})
            .setRename(true)
    };

    assertThrows(MeilisearchApiException.class, () -> {
        client.swapIndexes(params);
    });
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a5ec2f and 9a991c4.

📒 Files selected for processing (2)
  • src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java (1 hunks)
🔇 Additional comments (1)
src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java (1)

102-137: Excellent test coverage for multiple index pairs.

This test effectively validates that multiple swap operations are serialized correctly as a JSON array. The array structure validation (lines 134-136) is particularly valuable, ensuring the request body is properly formatted as an array rather than individual objects.

@curquiza curquiza changed the title Feat/support meilisearch 1.18 Add features of meilisearch 1.18 (queryVector and index renaming) Nov 21, 2025
@curquiza curquiza added the enhancement New feature or request label Nov 21, 2025
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

Hey @yamiSukehiro2907 can you remove the data.ms?

Also, can you fix the tests in the CI?

Thanks for your pR

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a991c4 and 9d142b3.

📒 Files selected for processing (1)
  • build.gradle (1 hunks)

@yamiSukehiro2907
Copy link
Author

@curquiza
Updated request path assertions to align with MockWebServer’s double-slash behavior, fixing the failing tests.

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

🧹 Nitpick comments (1)
src/test/java/com/meilisearch/sdk/SwapIndexRenameTest.java (1)

33-58: Relax path assertion to avoid coupling to double‑slash quirk

The comment notes the double slash in the recorded path; asserting equalTo("//swap-indexes") hard‑codes that behavior into the test. To keep the test stable if the base URL handling is later cleaned up, consider matching only the tail of the path:

-        assertThat(req.getMethod(), equalTo("POST"));
-        // FIX: Actual path contains double slash
-        assertThat(req.getPath(), equalTo("//swap-indexes"));
+        assertThat(req.getMethod(), equalTo("POST"));
+        assertThat(req.getPath(), endsWith("/swap-indexes"));

This still validates the correct endpoint while tolerating either /swap-indexes or //swap-indexes.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between baf7c67 and eb7f772.

📒 Files selected for processing (5)
  • build.gradle (8 hunks)
  • src/main/java/com/meilisearch/sdk/IndexesHandler.java (2 hunks)
  • src/test/java/com/meilisearch/sdk/IndexRenameTest.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java (1 hunks)
  • src/test/java/com/meilisearch/sdk/SwapIndexRenameTest.java (1 hunks)
🔇 Additional comments (3)
src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java (1)

31-55: Good coverage of queryVector deserialization through the public search API

This test cleanly validates the new queryVector field via Client.index(...).search(...) and asserts both size and contents; setup/teardown with MockWebServer and JUnit 5 look correct.

build.gradle (1)

48-77: Upgrade legacy MockWebServer to align with JUnit 6

The OkHttp version alignment (okhttp 5.3.0 and mockwebserver 5.3.0) is correct, but the build has a version mismatch: the legacy okhttp3.mockwebserver artifact is considered obsolete and depends on JUnit 4, yet your project uses JUnit 6 (junit-jupiter 6.0.1).

This pairing risks package incompatibilities and misses improvements in the newer API. Use the new mockwebserver3 artifacts, with mockwebserver3-junit5 for JUnit 5 integrations.

Verify that mockwebserver3-junit5 supports JUnit 6, or upgrade accordingly. You can also remove the redundant testImplementation 'com.squareup.okhttp3:okhttp:5.3.0' since tests already see it via the api dependency.

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

32-52: Align rename test with Meilisearch PATCH /indexes contract

To match the Meilisearch index update API and the updateIndexUid implementation fix, this test should assert the uid field in the payload, not indexUid. You can also make the path assertion less brittle with endsWith:

-        assertThat(req.getMethod(), equalTo("PATCH"));
-        // FIX: Actual path includes double slash
-        assertThat(req.getPath(), equalTo("//indexes/oldIndex"));
+        assertThat(req.getMethod(), equalTo("PATCH"));
+        assertThat(req.getPath(), endsWith("/indexes/oldIndex"));
@@
-        String body = req.getBody().readUtf8();
-        assertThat(body, containsString("\"indexUid\":\"newIndex\""));
+        String body = req.getBody().readUtf8();
+        assertThat(body, containsString("\"uid\":\"newIndex\""));
         assertThat(req.getHeader("Authorization"), equalTo("Bearer masterKey"));

This way the test validates the correct field name expected by the server while remaining tolerant to minor base‑URL formatting differences.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.18.0] Add queryVector to search responses and support index renaming

2 participants