Skip to content
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

Make MultiSearchItem.status optional #660

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG] JarHell caused by latest software.amazon.awssdk 2.20.141 ([#616](https://github.com/opensearch-project/opensearch-java/pull/616))
- Don't over-allocate in HeapBufferedAsyncEntityConsumer in order to consume the response ([#620](https://github.com/opensearch-project/opensearch-java/pull/620))
- Fixed CVE-2976 + added CVE checker ([#624](https://github.com/opensearch-project/opensearch-java/pull/624))
- Fix deserialization of MsearchTemplateResponse ([#660](https://github.com/opensearch-project/opensearch-java/pull/660))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDocument> extends SearchResponse<TDocument> {
private final int status;
@Nullable
private final Integer status;

// ---------------------------------------------------------------------------------------------

private MultiSearchItem(Builder<TDocument> builder) {
super(builder);

this.status = ApiTypeHelper.requireNonNull(builder.status, this, "status");
this.status = builder.status;

}

Expand All @@ -62,17 +63,21 @@ public static <TDocument> MultiSearchItem<TDocument> of(Function<Builder<TDocume
}

/**
* Required - API name: {@code status}
* API name: {@code status}
*/
public final int status() {
@Nullable
public final Integer status() {
return this.status;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

super.serializeInternal(generator, mapper);
generator.writeKey("status");
generator.write(this.status);

if (this.status != null) {
generator.writeKey("status");
generator.write(this.status);
}

}

Expand All @@ -85,12 +90,13 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
public static class Builder<TDocument> extends SearchResponse.AbstractBuilder<TDocument, Builder<TDocument>>
implements
ObjectBuilder<MultiSearchItem<TDocument>> {
@Nullable
private Integer status;

/**
* Required - API name: {@code status}
* API name: {@code status}
*/
public final Builder<TDocument> status(int value) {
public final Builder<TDocument> status(@Nullable Integer value) {
this.status = value;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a multi search template example is not present, it would be great to add it to the guides and working samples.

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<SimpleDoc> sendTemplateRequest(String index, String title, boolean suggs, boolean aggs)
throws IOException {
return javaClient().searchTemplate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading