Search in sources :

Example 66 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.

the class ElasticsearchIO method getBackendVersion.

static int getBackendVersion(ConnectionConfiguration connectionConfiguration) {
    try (RestClient restClient = connectionConfiguration.createClient()) {
        Request request = new Request("GET", "");
        Response response = restClient.performRequest(request);
        JsonNode jsonNode = parseResponse(response.getEntity());
        int backendVersion = Integer.parseInt(jsonNode.path("version").path("number").asText().substring(0, 1));
        checkArgument(VALID_CLUSTER_VERSIONS.contains(backendVersion), "The Elasticsearch version to connect to is %s.x. " + "This version of the ElasticsearchIO is only compatible with " + "Elasticsearch v7.x, v6.x, v5.x and v2.x", backendVersion);
        return backendVersion;
    } catch (IOException e) {
        throw new IllegalArgumentException("Cannot get Elasticsearch version", e);
    }
}
Also used : Response(org.elasticsearch.client.Response) RestClient(org.elasticsearch.client.RestClient) Request(org.elasticsearch.client.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 67 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.

the class ElasticsearchIOTestUtils method deleteIndex.

static void deleteIndex(RestClient restClient, String index) throws IOException {
    try {
        closeIndex(restClient, index);
        Request request = new Request("DELETE", String.format("/%s", index));
        restClient.performRequest(request);
    } catch (IOException e) {
        // so when the first tests is run, the index does not exist yet
        if (!e.getMessage().contains("index_not_found_exception")) {
            throw e;
        }
    }
}
Also used : Request(org.elasticsearch.client.Request) IOException(java.io.IOException)

Example 68 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.

the class ElasticsearchIOTestUtils method flushAndRefreshAllIndices.

static void flushAndRefreshAllIndices(RestClient restClient) throws IOException {
    Request request = new Request("POST", "/_flush");
    restClient.performRequest(request);
    request = new Request("POST", "/_refresh");
    restClient.performRequest(request);
}
Also used : Request(org.elasticsearch.client.Request)

Example 69 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.

the class ElasticsearchIOTestUtils method closeIndex.

private static void closeIndex(RestClient restClient, String index) throws IOException {
    Request request = new Request("POST", String.format("/%s/_close", index));
    restClient.performRequest(request);
}
Also used : Request(org.elasticsearch.client.Request)

Example 70 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.

the class ElasticsearchIOTestUtils method createIndex.

public static void createIndex(RestClient restClient, String indexName) throws IOException {
    deleteIndex(restClient, indexName);
    Request request = new Request("PUT", String.format("/%s", indexName));
    restClient.performRequest(request);
}
Also used : Request(org.elasticsearch.client.Request)

Aggregations

Request (org.elasticsearch.client.Request)54 Response (org.elasticsearch.client.Response)34 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 IOException (java.io.IOException)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 HttpEntity (org.apache.http.HttpEntity)11 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 StringEntity (org.apache.http.entity.StringEntity)6 RestClient (org.elasticsearch.client.RestClient)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 Locale (java.util.Locale)5 ContentType (org.apache.http.entity.ContentType)5