use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient 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);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project janusgraph by JanusGraph.
the class RestClientSetup method connect.
public ElasticSearchClient connect(Configuration config) throws IOException {
log.debug("Configuring RestClient");
final List<HttpHost> hosts = new ArrayList<>();
final int defaultPort = config.has(INDEX_PORT) ? config.get(INDEX_PORT) : ElasticSearchIndex.HOST_PORT_DEFAULT;
final String httpScheme = config.get(ElasticSearchIndex.SSL_ENABLED) ? "https" : "http";
for (String host : config.get(INDEX_HOSTS)) {
String[] hostStringParts = host.split(":");
String hostname = hostStringParts[0];
int hostPort = defaultPort;
if (hostStringParts.length == 2)
hostPort = Integer.parseInt(hostStringParts[1]);
log.debug("Configured remote host: {} : {}", hostname, hostPort);
hosts.add(new HttpHost(hostname, hostPort, httpScheme));
}
final RestClient rc = getRestClient(hosts.toArray(new HttpHost[hosts.size()]), config);
final int scrollKeepAlive = config.get(ElasticSearchIndex.ES_SCROLL_KEEP_ALIVE);
Preconditions.checkArgument(scrollKeepAlive >= 1, "Scroll keep-alive should be greater than or equal to 1");
final boolean useMappingTypesForES7 = config.get(ElasticSearchIndex.USE_MAPPING_FOR_ES7);
final RestElasticSearchClient client = getElasticSearchClient(rc, scrollKeepAlive, useMappingTypesForES7);
if (config.has(ElasticSearchIndex.BULK_REFRESH)) {
client.setBulkRefresh(config.get(ElasticSearchIndex.BULK_REFRESH));
}
Integer retryOnConflict = config.has(ElasticSearchIndex.RETRY_ON_CONFLICT) ? config.get(ElasticSearchIndex.RETRY_ON_CONFLICT) : null;
client.setRetryOnConflict(retryOnConflict);
return client;
}
Aggregations