use of org.elasticsearch.client.RestHighLevelClient in project beam by apache.
the class HadoopFormatIOElasticIT method prepareElasticIndex.
private static void prepareElasticIndex() throws IOException {
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(options.getElasticServerIp(), options.getElasticServerPort(), "http")));
for (int i = 0; i < 1000; i++) {
IndexRequest request = new IndexRequest(ELASTIC_INDEX_NAME).source(createElasticRow(i));
client.index(request, RequestOptions.DEFAULT);
}
}
use of org.elasticsearch.client.RestHighLevelClient in project beam by apache.
the class HadoopFormatIOElasticTest method prepareElasticIndex.
private static void prepareElasticIndex() throws IOException {
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearch.getContainerIpAddress(), elasticsearch.getMappedPort(9200), "http")));
for (int i = 0; i < TEST_DATA_ROW_COUNT; i++) {
IndexRequest request = new IndexRequest(ELASTIC_INDEX_NAME).source(createElasticRow(ELASTIC_TYPE_ID_PREFIX + i, "Faraday" + i));
client.index(request, RequestOptions.DEFAULT);
}
}
use of org.elasticsearch.client.RestHighLevelClient in project hazelcast by hazelcast.
the class BaseElasticTest method setUpBase.
@Before
public void setUpBase() {
if (elasticClient == null) {
elasticClient = new RestHighLevelClient(elasticClientSupplier().get());
}
cleanElasticData();
if (hz == null) {
hz = createHazelcastInstance();
}
results = hz.getList("results");
results.clear();
}
use of org.elasticsearch.client.RestHighLevelClient in project graylog2-server by Graylog2.
the class RestHighLevelClientProvider method buildClient.
private RestHighLevelClient buildClient(List<URI> hosts, Duration connectTimeout, Duration socketTimeout, int maxTotalConnections, int maxTotalConnectionsPerRoute, boolean useExpectContinue, boolean muteElasticsearchDeprecationWarnings, CredentialsProvider credentialsProvider) {
final HttpHost[] esHosts = hosts.stream().map(uri -> new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())).toArray(HttpHost[]::new);
final RestClientBuilder restClientBuilder = RestClient.builder(esHosts).setRequestConfigCallback(requestConfig -> requestConfig.setConnectTimeout(Math.toIntExact(connectTimeout.toMilliseconds())).setSocketTimeout(Math.toIntExact(socketTimeout.toMilliseconds())).setExpectContinueEnabled(useExpectContinue).setAuthenticationEnabled(true)).setHttpClientConfigCallback(httpClientConfig -> {
httpClientConfig.setMaxConnTotal(maxTotalConnections).setMaxConnPerRoute(maxTotalConnectionsPerRoute).setDefaultCredentialsProvider(credentialsProvider);
if (muteElasticsearchDeprecationWarnings) {
httpClientConfig.addInterceptorFirst(new ElasticsearchFilterDeprecationWarningsInterceptor());
}
return httpClientConfig;
});
return new RestHighLevelClient(restClientBuilder);
}
use of org.elasticsearch.client.RestHighLevelClient in project gora by apache.
the class ElasticsearchStore method createClient.
public static RestHighLevelClient createClient(ElasticsearchParameters parameters) {
RestClientBuilder clientBuilder = RestClient.builder(new HttpHost(parameters.getHost(), parameters.getPort()));
// Choosing the authentication method.
switch(parameters.getAuthenticationType()) {
case BASIC:
if (parameters.getUsername() != null && parameters.getPassword() != null) {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(parameters.getUsername(), parameters.getPassword()));
clientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
} else {
throw new IllegalArgumentException("Missing username or password for BASIC authentication.");
}
break;
case TOKEN:
if (parameters.getAuthorizationToken() != null) {
Header[] defaultHeaders = new Header[] { new BasicHeader("Authorization", parameters.getAuthorizationToken()) };
clientBuilder.setDefaultHeaders(defaultHeaders);
} else {
throw new IllegalArgumentException("Missing authorization token for TOKEN authentication.");
}
break;
case APIKEY:
if (parameters.getApiKeyId() != null && parameters.getApiKeySecret() != null) {
String apiKeyAuth = Base64.getEncoder().encodeToString((parameters.getApiKeyId() + ":" + parameters.getApiKeySecret()).getBytes(StandardCharsets.UTF_8));
Header[] defaultHeaders = new Header[] { new BasicHeader("Authorization", "ApiKey " + apiKeyAuth) };
clientBuilder.setDefaultHeaders(defaultHeaders);
} else {
throw new IllegalArgumentException("Missing API Key ID or API Key Secret for APIKEY authentication.");
}
break;
}
if (parameters.getConnectTimeout() != 0) {
clientBuilder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(parameters.getConnectTimeout()));
}
if (parameters.getSocketTimeout() != 0) {
clientBuilder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setSocketTimeout(parameters.getSocketTimeout()));
}
if (parameters.getIoThreadCount() != 0) {
clientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(parameters.getIoThreadCount()).build()));
}
return new RestHighLevelClient(clientBuilder);
}
Aggregations