use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testBulkToOpenSearchDashboardsIndex.
public void testBulkToOpenSearchDashboardsIndex() throws IOException {
Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testCreateIndex.
public void testCreateIndex() throws IOException {
Request request = new Request("PUT", "/_opensearch_dashboards/" + indexName);
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testDeleteByQueryFromOpenSearchDashboardsIndex.
public void testDeleteByQueryFromOpenSearchDashboardsIndex() throws IOException {
Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n" + "{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"2\" } }\n{ \"baz\" : \"tag\" }\n");
request.addParameter("refresh", "true");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
Request dbqRequest = new Request("POST", "/_opensearch_dashboards/" + indexName + "/_delete_by_query");
dbqRequest.setJsonEntity("{ \"query\" : { \"match_all\" : {} } }\n");
Response dbqResponse = client().performRequest(dbqRequest);
assertThat(dbqResponse.getStatusLine().getStatusCode(), is(200));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testScrollingDocs.
public void testScrollingDocs() throws IOException {
Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n" + "{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"2\" } }\n{ \"baz\" : \"tag\" }\n" + "{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"3\" } }\n{ \"baz\" : \"tag\" }\n");
request.addParameter("refresh", "true");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
Request searchRequest = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_search");
searchRequest.setJsonEntity("{ \"size\" : 1,\n\"query\" : { \"match_all\" : {} } }\n");
searchRequest.addParameter("scroll", "1m");
response = client().performRequest(searchRequest);
assertThat(response.getStatusLine().getStatusCode(), is(200));
Map<String, Object> map = XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
assertNotNull(map.get("_scroll_id"));
String scrollId = (String) map.get("_scroll_id");
Request scrollRequest = new Request("POST", "/_opensearch_dashboards/_search/scroll");
scrollRequest.addParameter("scroll_id", scrollId);
scrollRequest.addParameter("scroll", "1m");
response = client().performRequest(scrollRequest);
assertThat(response.getStatusLine().getStatusCode(), is(200));
map = XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
assertNotNull(map.get("_scroll_id"));
scrollId = (String) map.get("_scroll_id");
Request clearScrollRequest = new Request("DELETE", "/_opensearch_dashboards/_search/scroll");
clearScrollRequest.addParameter("scroll_id", scrollId);
response = client().performRequest(clearScrollRequest);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testRefresh.
public void testRefresh() throws IOException {
Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
request = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_refresh");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
Request getRequest = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_doc/1");
Response getResponse = client().performRequest(getRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
String responseBody = EntityUtils.toString(getResponse.getEntity());
assertThat(responseBody, containsString("foo"));
assertThat(responseBody, containsString("bar"));
}
Aggregations