use of co.elastic.clients.transport.rest_client.RestClientTransport in project core-ng-project by neowu.
the class ElasticSearchImpl method initialize.
// initialize will be called in startup hook, no need to synchronize
public void initialize() {
if (client == null) {
// initialize can be called by initSearch explicitly during test,
RestClientBuilder builder = RestClient.builder(hosts);
builder.setRequestConfigCallback(config -> config.setSocketTimeout((int) timeout.toMillis()).setConnectionRequestTimeout(// timeout of requesting connection from connection pool
(int) timeout.toMillis()));
builder.setHttpClientConfigCallback(config -> config.setMaxConnTotal(100).setMaxConnPerRoute(100).setKeepAliveStrategy((response, context) -> Duration.ofSeconds(30).toMillis()));
builder.setHttpClientConfigCallback(config -> config.addInterceptorFirst(new ElasticSearchLogInterceptor()));
restClient = builder.build();
client = new ElasticsearchClient(new RestClientTransport(restClient, new JacksonJsonpMapper(JSONMapper.OBJECT_MAPPER)));
}
}
use of co.elastic.clients.transport.rest_client.RestClientTransport in project micronaut-elasticsearch by micronaut-projects.
the class DefaultElasticsearchClientFactory method elasticsearchTransport.
/**
* @param elasticsearchConfiguration The {@link DefaultElasticsearchConfigurationProperties} object.
* @param objectMapper The {@link ObjectMapper} object.
* @return The {@link ElasticsearchTransport}.
* @since 4.2.0
*/
@Singleton
@Bean(preDestroy = "close")
ElasticsearchTransport elasticsearchTransport(DefaultElasticsearchConfigurationProperties elasticsearchConfiguration, ObjectMapper objectMapper) {
RestClient restClient = restClientBuilder(elasticsearchConfiguration).build();
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper(objectMapper));
return transport;
}
use of co.elastic.clients.transport.rest_client.RestClientTransport in project syncope by apache.
the class ElasticsearchClientFactoryBean method getObject.
@Override
public ElasticsearchClient getObject() throws Exception {
synchronized (this) {
if (client == null) {
RestClientBuilder builder = RestClient.builder(hosts.toArray(HttpHost[]::new));
if (username != null && password != null) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
builder.setHttpClientConfigCallback(b -> b.setDefaultCredentialsProvider(credentialsProvider));
} else if (serviceToken != null) {
builder.setDefaultHeaders(new Header[] { new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + serviceToken) });
} else if (apiKeyId != null && apiKeySecret != null) {
String apiKeyAuth = Base64.getEncoder().encodeToString((apiKeyId + ":" + apiKeySecret).getBytes(StandardCharsets.UTF_8));
builder.setDefaultHeaders(new Header[] { new BasicHeader(HttpHeaders.AUTHORIZATION, "ApiKey " + apiKeyAuth) });
}
restClient = builder.build();
client = new ElasticsearchClient(new RestClientTransport(restClient, new JacksonJsonpMapper()));
}
}
return client;
}
Aggregations