Search in sources :

Example 21 with Response

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));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 22 with Response

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));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 23 with Response

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));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 24 with Response

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));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 25 with Response

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"));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

Response (org.opensearch.client.Response)134 Request (org.opensearch.client.Request)113 ResponseException (org.opensearch.client.ResponseException)24 Map (java.util.Map)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 ArrayList (java.util.ArrayList)17 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)16 RestClient (org.opensearch.client.RestClient)15 HashMap (java.util.HashMap)14 RequestOptions (org.opensearch.client.RequestOptions)12 ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 IndexRequest (org.opensearch.action.index.IndexRequest)11 IOException (java.io.IOException)10 List (java.util.List)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 Version (org.opensearch.Version)8 WriteRequest (org.opensearch.action.support.WriteRequest)8 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)7 IndexResponse (org.opensearch.action.index.IndexResponse)7 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)7