From d269c4187607c83f14cf1a9b7a6d00fff7eeb1ba Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Fri, 13 Oct 2023 09:44:17 +1300 Subject: [PATCH] Make `MultiSearchItem.status` optional (#660) * Add failing msearchTemplate integration test Signed-off-by: Thomas Farr * Make `MultiSearchItem.status` optional Signed-off-by: Thomas Farr * Add changelog entry Signed-off-by: Thomas Farr * spotlessApply Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr (cherry picked from commit d2916e42f7c1af931192bb48a6079948d6af1535) --- CHANGELOG.md | 1 + .../core/msearch/MultiSearchItem.java | 24 +++++++++++------- .../AbstractSearchTemplateRequestIT.java | 25 +++++++++++++++++++ .../json/jackson/JacksonJsonpParserTest.java | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fda0392554..97a6a762ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed CVE-2976 + added CVE checker ([#624](https://github.com/opensearch-project/opensearch-java/pull/624)) - Fix parsing of GetFieldMappingResponse ([#641](https://github.com/opensearch-project/opensearch-java/pull/641)) - Fix TermvectorsResponse for optional fields ([#642](https://github.com/opensearch-project/opensearch-java/pull/642)) +- Fix deserialization of MsearchTemplateResponse ([#660](https://github.com/opensearch-project/opensearch-java/pull/660)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/msearch/MultiSearchItem.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/msearch/MultiSearchItem.java index 65007621c4..8e245a4289 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/msearch/MultiSearchItem.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/msearch/MultiSearchItem.java @@ -35,25 +35,26 @@ import jakarta.json.stream.JsonGenerator; import java.util.function.Function; import java.util.function.Supplier; +import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.ObjectBuilderDeserializer; import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.opensearch.core.SearchResponse; -import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; // typedef: _global.msearch.MultiSearchItem public class MultiSearchItem extends SearchResponse { - private final int status; + @Nullable + private final Integer status; // --------------------------------------------------------------------------------------------- private MultiSearchItem(Builder builder) { super(builder); - this.status = ApiTypeHelper.requireNonNull(builder.status, this, "status"); + this.status = builder.status; } @@ -62,17 +63,21 @@ public static MultiSearchItem of(Function extends SearchResponse.AbstractBuilder> implements ObjectBuilder> { + @Nullable private Integer status; /** - * Required - API name: {@code status} + * API name: {@code status} */ - public final Builder status(int value) { + public final Builder status(@Nullable Integer value) { this.status = value; return this; } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractSearchTemplateRequestIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractSearchTemplateRequestIT.java index 9e029fe95f..7b30b77786 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractSearchTemplateRequestIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractSearchTemplateRequestIT.java @@ -85,6 +85,31 @@ public void testTemplateSearchAggregations() throws Exception { } + @Test + public void testMultiSearchTemplate() throws Exception { + var index = "test-msearch-template"; + createDocuments(index); + + var searchResponse = javaClient().msearchTemplate( + request -> request.searchTemplates( + r -> r.header(h -> h.index(index)) + .body( + t -> t.id(TEST_SEARCH_TEMPLATE) + .params("title", JsonData.of("Document")) + .params("suggs", JsonData.of(false)) + .params("aggs", JsonData.of(false)) + ) + ), + SimpleDoc.class + ); + + assertEquals(1, searchResponse.responses().size()); + var response = searchResponse.responses().get(0); + assertTrue(response.isResult()); + assertNull(response.result().status()); + assertEquals(4, response.result().hits().hits().size()); + } + private SearchTemplateResponse sendTemplateRequest(String index, String title, boolean suggs, boolean aggs) throws IOException { return javaClient().searchTemplate( diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/json/jackson/JacksonJsonpParserTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/json/jackson/JacksonJsonpParserTest.java index be80a45c8b..cc8426562d 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/json/jackson/JacksonJsonpParserTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/json/jackson/JacksonJsonpParserTest.java @@ -186,7 +186,7 @@ public void testMultiSearchResponse() { assertEquals(2, response.responses().size()); assertEquals(404, response.responses().get(0).failure().status()); - assertEquals(200, response.responses().get(1).result().status()); + assertEquals((Integer) 200, response.responses().get(1).result().status()); } public static class AttributedJacksonJsonpMapper extends JacksonJsonpMapper {