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

Fixing partial success results for msearch template (#709) (#714) #724

Merged
merged 1 commit into from
Nov 14, 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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased 2.x]
### Added

### Dependencies

### Changed

### Deprecated

### Removed

### Fixed
- Fix partial success results for msearch_template ([#709](https://github.com/opensearch-project/opensearch-java/pull/709))

### Security

## [2.8.0] - 01/11/2023
### Added
- Added support for indexing and search index settings ([#667](https://github.com/opensearch-project/opensearch-java/pull/667))

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ private enum Kind {

private final ErrorCause error;

private final int status;
private final Integer status;

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

private ErrorResponse(Builder builder) {

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

}

Expand All @@ -87,7 +87,7 @@ public final ErrorCause error() {
/**
* Required - API name: {@code status}
*/
public final int status() {
public final Integer status() {
return this.status;
}

Expand All @@ -105,8 +105,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("error");
this.error.serialize(generator, mapper);

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

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ public void testClusterUpdateSettingNonExistent() throws IOException {
fail();
} catch (OpenSearchException e) {
assertNotNull(e);
assertEquals(e.response().status(), 400);
assertEquals(
e.getMessage(),
"Request failed: [illegal_argument_exception] " + "transient setting [no_idea_what_you_are_talking_about], not recognized"
);
assertEquals(e.response().status().intValue(), 400);
assertTrue(e.getMessage().contains("transient setting [no_idea_what_you_are_talking_about], not recognized"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void testDataIngestion() throws Exception {
assertTrue(msearch.responses().get(0).isResult());
assertEquals(1, msearch.responses().get(0).result().hits().hits().size());
assertTrue(msearch.responses().get(1).isFailure());
assertEquals(404, msearch.responses().get(1).failure().status());
assertEquals(404, msearch.responses().get(1).failure().status().intValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
package org.opensearch.client.opensearch.integTest;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.opensearch._types.Refresh;
import org.opensearch.client.opensearch._types.mapping.Property;
import org.opensearch.client.opensearch.core.PutScriptRequest;
import org.opensearch.client.opensearch.core.SearchTemplateResponse;
import org.opensearch.client.opensearch.core.msearch_template.RequestItem;

public abstract class AbstractSearchTemplateRequestIT extends OpenSearchJavaClientTestCase {

Expand Down Expand Up @@ -87,27 +89,43 @@ public void testTemplateSearchAggregations() throws Exception {

@Test
public void testMultiSearchTemplate() throws Exception {
System.out.println("Multi search template test");
var index = "test-msearch-template";
createDocuments(index);

RequestItem requestItem = RequestItem.of(
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))
)
);
// adding a request to non existing template to test partial results
RequestItem requestItem2 = RequestItem.of(
r -> r.header(h -> h.index(index))
.body(
t -> t.id("my-other-search-template")
.params("title", JsonData.of("Document"))
.params("suggs", JsonData.of(false))
.params("aggs", JsonData.of(false))
)
);

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))
)
),
request -> request.searchTemplates(List.of(requestItem, requestItem2)),
SimpleDoc.class
);

assertEquals(1, searchResponse.responses().size());
assertEquals(2, searchResponse.responses().size());
var response = searchResponse.responses().get(0);
assertTrue(response.isResult());
assertNull(response.result().status());
assertEquals(4, response.result().hits().hits().size());
var failureResponse = searchResponse.responses().get(1);
assertTrue(failureResponse.isFailure());
assertNull(failureResponse.failure().status());
}

private SearchTemplateResponse<SimpleDoc> sendTemplateRequest(String index, String title, boolean suggs, boolean aggs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testMultiSearchResponse() {
MsearchResponse<Foo> response = fromJson(json, MsearchResponse.class, mapper);

assertEquals(2, response.responses().size());
assertEquals(404, response.responses().get(0).failure().status());
assertEquals(404, response.responses().get(0).failure().status().intValue());
assertEquals((Integer) 200, response.responses().get(1).result().status());
}

Expand Down
Loading