Skip to content

Commit

Permalink
Correct RHLC searchTemplate & mtermVectors endpoints to have leading …
Browse files Browse the repository at this point in the history
…slash (opensearch-project#14465)

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored and harshavamsi committed Jul 12, 2024
1 parent 3361812 commit dfb0ae0
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix handling of Short and Byte data types in ScriptProcessor ingest pipeline ([#14379](https://github.com/opensearch-project/OpenSearch/issues/14379))
- Switch to iterative version of WKT format parser ([#14086](https://github.com/opensearch-project/OpenSearch/pull/14086))
- Fix the computed max shards of cluster to avoid int overflow ([#14155](https://github.com/opensearch-project/OpenSearch/pull/14155))
- Fixed rest-high-level client searchTemplate & mtermVectors endpoints to have a leading slash ([#14465](https://github.com/opensearch-project/OpenSearch/pull/14465))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static Request searchTemplate(SearchTemplateRequest searchTemplateRequest) throw
Request request;

if (searchTemplateRequest.isSimulate()) {
request = new Request(HttpGet.METHOD_NAME, "_render/template");
request = new Request(HttpGet.METHOD_NAME, "/_render/template");
} else {
SearchRequest searchRequest = searchTemplateRequest.getRequest();
String endpoint = endpoint(searchRequest.indices(), "_search/template");
Expand Down Expand Up @@ -803,8 +803,7 @@ static Request termVectors(TermVectorsRequest tvrequest) throws IOException {
}

static Request mtermVectors(MultiTermVectorsRequest mtvrequest) throws IOException {
String endpoint = "_mtermvectors";
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
Request request = new Request(HttpGet.METHOD_NAME, "/_mtermvectors");
request.setEntity(createEntity(mtvrequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public void testOpenExistingIndex() throws IOException {
closeIndex(index);
ResponseException exception = expectThrows(
ResponseException.class,
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"))
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, "/" + index + "/_search"))
);
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
assertThat(exception.getMessage().contains(index), equalTo(true));
Expand All @@ -714,7 +714,7 @@ public void testOpenExistingIndex() throws IOException {
);
assertTrue(openIndexResponse.isAcknowledged());

Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, "/" + index + "/_search"));
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
}

Expand Down Expand Up @@ -771,7 +771,7 @@ public void testCloseExistingIndex() throws IOException {

ResponseException exception = expectThrows(
ResponseException.class,
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, indexResult.getIndex() + "/_search"))
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, "/" + indexResult.getIndex() + "/_search"))
);
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
assertThat(exception.getMessage().contains(indexResult.getIndex()), equalTo(true));
Expand Down Expand Up @@ -1270,7 +1270,7 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException {
assertThat(getAliasesResponse.getException(), nullValue());
}
createIndex(index, Settings.EMPTY);
client().performRequest(new Request(HttpPut.METHOD_NAME, index + "/_alias/" + alias));
client().performRequest(new Request(HttpPut.METHOD_NAME, "/" + index + "/_alias/" + alias));
{
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index");
GetAliasesResponse getAliasesResponse = execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testRankEvalRequest() throws IOException {
}

// now try this when test2 is closed
client().performRequest(new Request("POST", "index2/_close"));
client().performRequest(new Request("POST", "/index2/_close"));
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ public void testRenderSearchTemplate() throws Exception {

// Verify that the resulting REST request looks as expected.
Request request = RequestConverters.searchTemplate(searchTemplateRequest);
String endpoint = "_render/template";
String endpoint = "/_render/template";

assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals(endpoint, request.getEndpoint());
Expand Down Expand Up @@ -1565,7 +1565,7 @@ public void testMultiTermVectors() throws IOException {

Request request = RequestConverters.mtermVectors(mtvRequest);
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("_mtermvectors", request.getEndpoint());
assertEquals("/_mtermvectors", request.getEndpoint());
assertToXContentBody(mtvRequest, request.getEntity());
}

Expand All @@ -1585,7 +1585,7 @@ public void testMultiTermVectorsWithType() throws IOException {

Request request = RequestConverters.mtermVectors(mtvRequest);
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("_mtermvectors", request.getEndpoint());
assertEquals("/_mtermvectors", request.getEndpoint());
assertToXContentBody(mtvRequest, request.getEntity());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ public void testSearchWithSuggest() throws IOException {
}

public void testSearchWithWeirdScriptFields() throws Exception {
Request doc = new Request("PUT", "test/_doc/1");
Request doc = new Request("PUT", "/test/_doc/1");
doc.setJsonEntity("{\"field\":\"value\"}");
client().performRequest(doc);
client().performRequest(new Request("POST", "/test/_refresh"));
Expand Down Expand Up @@ -774,7 +774,7 @@ public void testSearchWithWeirdScriptFields() throws Exception {
public void testSearchWithDerivedFields() throws Exception {
// Just testing DerivedField definition from SearchSourceBuilder derivedField()
// We are not testing the full functionality here
Request doc = new Request("PUT", "test/_doc/1");
Request doc = new Request("PUT", "/test/_doc/1");
doc.setJsonEntity("{\"field\":\"value\"}");
client().performRequest(doc);
client().performRequest(new Request("POST", "/test/_refresh"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ public void onFailure(Exception e) {

protected void registerQueryScript(RestClient restClient) throws IOException {
// tag::register-script
Request scriptRequest = new Request("POST", "_scripts/title_search");
Request scriptRequest = new Request("POST", "/_scripts/title_search");
scriptRequest.setJsonEntity(
"{" +
" \"script\": {" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ private void createTestIndex() throws IOException {
}

private void createTestSnapshots() throws IOException {
Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repositoryName, snapshotName));
Request createSnapshot = new Request("put", String.format(Locale.ROOT, "/_snapshot/%s/%s", repositoryName, snapshotName));
createSnapshot.addParameter("wait_for_completion", "true");
createSnapshot.setJsonEntity("{\"indices\":\"" + indexName + "\"}");
Response response = highLevelClient().getLowLevelClient().performRequest(createSnapshot);
Expand Down

0 comments on commit dfb0ae0

Please sign in to comment.