Skip to content

Commit 9675c4f

Browse files
authored
Correct RHLC searchTemplate & mtermVectors endpoints to have leading slash (#14465)
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
1 parent b8c7819 commit 9675c4f

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3636
- Fix handling of Short and Byte data types in ScriptProcessor ingest pipeline ([#14379](https://github.com/opensearch-project/OpenSearch/issues/14379))
3737
- Switch to iterative version of WKT format parser ([#14086](https://github.com/opensearch-project/OpenSearch/pull/14086))
3838
- Fix the computed max shards of cluster to avoid int overflow ([#14155](https://github.com/opensearch-project/OpenSearch/pull/14155))
39+
- Fixed rest-high-level client searchTemplate & mtermVectors endpoints to have a leading slash ([#14465](https://github.com/opensearch-project/OpenSearch/pull/14465))
3940

4041
### Security
4142

client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static Request searchTemplate(SearchTemplateRequest searchTemplateRequest) throw
540540
Request request;
541541

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

805805
static Request mtermVectors(MultiTermVectorsRequest mtvrequest) throws IOException {
806-
String endpoint = "_mtermvectors";
807-
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
806+
Request request = new Request(HttpGet.METHOD_NAME, "/_mtermvectors");
808807
request.setEntity(createEntity(mtvrequest, REQUEST_BODY_CONTENT_TYPE));
809808
return request;
810809
}

client/rest-high-level/src/test/java/org/opensearch/client/IndicesClientIT.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ public void testOpenExistingIndex() throws IOException {
701701
closeIndex(index);
702702
ResponseException exception = expectThrows(
703703
ResponseException.class,
704-
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"))
704+
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, "/" + index + "/_search"))
705705
);
706706
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
707707
assertThat(exception.getMessage().contains(index), equalTo(true));
@@ -714,7 +714,7 @@ public void testOpenExistingIndex() throws IOException {
714714
);
715715
assertTrue(openIndexResponse.isAcknowledged());
716716

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

@@ -771,7 +771,7 @@ public void testCloseExistingIndex() throws IOException {
771771

772772
ResponseException exception = expectThrows(
773773
ResponseException.class,
774-
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, indexResult.getIndex() + "/_search"))
774+
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, "/" + indexResult.getIndex() + "/_search"))
775775
);
776776
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
777777
assertThat(exception.getMessage().contains(indexResult.getIndex()), equalTo(true));
@@ -1270,7 +1270,7 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException {
12701270
assertThat(getAliasesResponse.getException(), nullValue());
12711271
}
12721272
createIndex(index, Settings.EMPTY);
1273-
client().performRequest(new Request(HttpPut.METHOD_NAME, index + "/_alias/" + alias));
1273+
client().performRequest(new Request(HttpPut.METHOD_NAME, "/" + index + "/_alias/" + alias));
12741274
{
12751275
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index");
12761276
GetAliasesResponse getAliasesResponse = execute(

client/rest-high-level/src/test/java/org/opensearch/client/RankEvalIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void testRankEvalRequest() throws IOException {
121121
}
122122

123123
// now try this when test2 is closed
124-
client().performRequest(new Request("POST", "index2/_close"));
124+
client().performRequest(new Request("POST", "/index2/_close"));
125125
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
126126
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
127127
}

client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ public void testRenderSearchTemplate() throws Exception {
13991399

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

14041404
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
14051405
assertEquals(endpoint, request.getEndpoint());
@@ -1565,7 +1565,7 @@ public void testMultiTermVectors() throws IOException {
15651565

15661566
Request request = RequestConverters.mtermVectors(mtvRequest);
15671567
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
1568-
assertEquals("_mtermvectors", request.getEndpoint());
1568+
assertEquals("/_mtermvectors", request.getEndpoint());
15691569
assertToXContentBody(mtvRequest, request.getEntity());
15701570
}
15711571

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

15861586
Request request = RequestConverters.mtermVectors(mtvRequest);
15871587
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
1588-
assertEquals("_mtermvectors", request.getEndpoint());
1588+
assertEquals("/_mtermvectors", request.getEndpoint());
15891589
assertToXContentBody(mtvRequest, request.getEntity());
15901590
}
15911591

client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ public void testSearchWithSuggest() throws IOException {
727727
}
728728

729729
public void testSearchWithWeirdScriptFields() throws Exception {
730-
Request doc = new Request("PUT", "test/_doc/1");
730+
Request doc = new Request("PUT", "/test/_doc/1");
731731
doc.setJsonEntity("{\"field\":\"value\"}");
732732
client().performRequest(doc);
733733
client().performRequest(new Request("POST", "/test/_refresh"));
@@ -774,7 +774,7 @@ public void testSearchWithWeirdScriptFields() throws Exception {
774774
public void testSearchWithDerivedFields() throws Exception {
775775
// Just testing DerivedField definition from SearchSourceBuilder derivedField()
776776
// We are not testing the full functionality here
777-
Request doc = new Request("PUT", "test/_doc/1");
777+
Request doc = new Request("PUT", "/test/_doc/1");
778778
doc.setJsonEntity("{\"field\":\"value\"}");
779779
client().performRequest(doc);
780780
client().performRequest(new Request("POST", "/test/_refresh"));

client/rest-high-level/src/test/java/org/opensearch/client/documentation/SearchDocumentationIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ public void onFailure(Exception e) {
998998

999999
protected void registerQueryScript(RestClient restClient) throws IOException {
10001000
// tag::register-script
1001-
Request scriptRequest = new Request("POST", "_scripts/title_search");
1001+
Request scriptRequest = new Request("POST", "/_scripts/title_search");
10021002
scriptRequest.setJsonEntity(
10031003
"{" +
10041004
" \"script\": {" +

client/rest-high-level/src/test/java/org/opensearch/client/documentation/SnapshotClientDocumentationIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ private void createTestIndex() throws IOException {
827827
}
828828

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

0 commit comments

Comments
 (0)