Skip to content

Commit

Permalink
Fixing partial success results for msearch template (#709) (#714) (#724)
Browse files Browse the repository at this point in the history
* Fixing partial success results for msearch template

* Adding changelog

* Spotless apply

---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah authored Nov 14, 2023
1 parent 3491c33 commit e1b6c83
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
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

0 comments on commit e1b6c83

Please sign in to comment.