Search in sources :

Example 11 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class IndexingIT method assertCount.

private void assertCount(String index, int count) throws IOException {
    Request searchTestIndexRequest = new Request("POST", "/" + index + "/_search");
    searchTestIndexRequest.addParameter(TOTAL_HITS_AS_INT_PARAM, "true");
    searchTestIndexRequest.addParameter("filter_path", "hits.total");
    Response searchTestIndexResponse = client().performRequest(searchTestIndexRequest);
    assertEquals("{\"hits\":{\"total\":" + count + "}}", EntityUtils.toString(searchTestIndexResponse.getEntity(), StandardCharsets.UTF_8));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 12 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class JodaCompatibilityIT method testJodaBackedDocValueAndDateFields.

public void testJodaBackedDocValueAndDateFields() throws Exception {
    switch(CLUSTER_TYPE) {
        case OLD:
            Request createTestIndex = indexWithDateField("joda_time", "YYYY-MM-dd'T'HH:mm:ssZZ");
            createTestIndex.setOptions(ignoreWarnings());
            Response resp = client().performRequest(createTestIndex);
            assertEquals(HttpStatus.SC_OK, resp.getStatusLine().getStatusCode());
            postNewDoc("joda_time", 1);
            break;
        case MIXED:
            int minute = Booleans.parseBoolean(System.getProperty("tests.first_round")) ? 2 : 3;
            postNewDoc("joda_time", minute);
            Request search = dateRangeSearch("joda_time");
            search.setOptions(ignoreWarnings());
            performOnAllNodes(search, r -> assertEquals(HttpStatus.SC_OK, r.getStatusLine().getStatusCode()));
            break;
        case UPGRADED:
            postNewDoc("joda_time", 4);
            search = searchWithAgg("joda_time");
            search.setOptions(ignoreWarnings());
            // making sure all nodes were used for search
            performOnAllNodes(search, r -> assertResponseHasAllDocuments(r));
            break;
    }
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 13 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class JodaCompatibilityIT method postNewDoc.

private void postNewDoc(String endpoint, int minute) throws IOException {
    Request putDoc = new Request("POST", endpoint + "/_doc");
    putDoc.addParameter("refresh", "true");
    putDoc.addParameter("wait_for_active_shards", "all");
    putDoc.setJsonEntity("{\n" + "  \"datetime\": \"2020-01-01T00:00:0" + minute + "+01:00\"\n" + "}");
    Response resp = client().performRequest(putDoc);
    assertEquals(HttpStatus.SC_CREATED, resp.getStatusLine().getStatusCode());
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 14 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class JodaCompatibilityIT method testJavaBackedDocValueAndDateFields.

public void testJavaBackedDocValueAndDateFields() throws Exception {
    switch(CLUSTER_TYPE) {
        case OLD:
            Request createTestIndex = indexWithDateField("java_time", "8yyyy-MM-dd'T'HH:mm:ssXXX");
            Response resp = client().performRequest(createTestIndex);
            assertEquals(HttpStatus.SC_OK, resp.getStatusLine().getStatusCode());
            postNewDoc("java_time", 1);
            break;
        case MIXED:
            int minute = Booleans.parseBoolean(System.getProperty("tests.first_round")) ? 2 : 3;
            postNewDoc("java_time", minute);
            Request search = dateRangeSearch("java_time");
            Response searchResp = client().performRequest(search);
            assertEquals(HttpStatus.SC_OK, searchResp.getStatusLine().getStatusCode());
            break;
        case UPGRADED:
            postNewDoc("java_time", 4);
            search = searchWithAgg("java_time");
            // making sure all nodes were used for search
            performOnAllNodes(search, r -> assertResponseHasAllDocuments(r));
            break;
    }
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 15 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class RecoveryIT method testHistoryUUIDIsGenerated.

public void testHistoryUUIDIsGenerated() throws Exception {
    final String index = "index_history_uuid";
    if (CLUSTER_TYPE == ClusterType.OLD) {
        Settings.Builder settings = Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1).put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms");
        createIndex(index, settings.build());
    } else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
        ensureGreen(index);
        Request shardStatsRequest = new Request("GET", index + "/_stats");
        shardStatsRequest.addParameter("level", "shards");
        Response response = client().performRequest(shardStatsRequest);
        ObjectPath objectPath = ObjectPath.createFromResponse(response);
        List<Object> shardStats = objectPath.evaluate("indices." + index + ".shards.0");
        assertThat(shardStats, hasSize(2));
        String expectHistoryUUID = null;
        for (int shard = 0; shard < 2; shard++) {
            String nodeID = objectPath.evaluate("indices." + index + ".shards.0." + shard + ".routing.node");
            String historyUUID = objectPath.evaluate("indices." + index + ".shards.0." + shard + ".commit.user_data.history_uuid");
            assertThat("no history uuid found for shard on " + nodeID, historyUUID, notNullValue());
            if (expectHistoryUUID == null) {
                expectHistoryUUID = historyUUID;
            } else {
                assertThat("different history uuid found for shard on " + nodeID, historyUUID, equalTo(expectHistoryUUID));
            }
        }
    }
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Request(org.opensearch.client.Request) ArrayList(java.util.ArrayList) List(java.util.List) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

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