use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project warn-report by saaavsaaa.
the class ElasticClient method search.
@Test
public void search() throws IOException {
String elasticsearchHost = "sl010a-analysisdb1:9200,sl010a-analysisdb2:9200,sl010a-analysisdb3:9200";
String[] elasticHosts = elasticsearchHost.split(",");
HttpHost[] httpHosts = new HttpHost[elasticHosts.length];
for (int i = 0; i < elasticHosts.length; i++) {
String ip = elasticHosts[i].split(":")[0];
String port = elasticHosts[i].split(":")[1];
httpHosts[i] = new HttpHost(ip, Integer.parseInt(port), "https");
}
RestClient restClient = RestClient.builder(httpHosts).setDefaultHeaders(new Header[] { new BasicHeader("Authorization", "Basic Q049ZGVtb3VzZXI6Q049ZGVtb3VzZXI=") }).build();
RestHighLevelClient client = new RestHighLevelClient(restClient);
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest);
System.out.println(searchResponse.getTotalShards());
}
Aggregations