use of org.elasticsearch.client.RestHighLevelClient in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentConfiguration method get.
/**
* returns an {@link ElasticsearchDocumentCollectionManagerFactory} instance
*
* @param builder the builder {@link RestClientBuilder}
* @return a manager factory instance
* @throws NullPointerException when builder is null
*/
public ElasticsearchDocumentCollectionManagerFactory get(RestClientBuilder builder) {
Objects.requireNonNull(builder, "builder is required");
RestHighLevelClient client = new RestHighLevelClient(builder);
return new ElasticsearchDocumentCollectionManagerFactory(client);
}
use of org.elasticsearch.client.RestHighLevelClient in project jnosql-diana-driver by eclipse.
the class EntityConverter method executeId.
private static void executeId(DocumentQuery query, RestHighLevelClient client, String index, QueryConverterResult select, List<DocumentEntity> entities) throws IOException {
String type = query.getDocumentCollection();
MultiGetRequest multiGetRequest = new MultiGetRequest();
select.getIds().stream().map(id -> new MultiGetRequest.Item(index, type, id)).forEach(multiGetRequest::add);
MultiGetResponse responses = client.multiGet(multiGetRequest);
Stream.of(responses.getResponses()).map(MultiGetItemResponse::getResponse).map(ElasticsearchEntry::of).filter(ElasticsearchEntry::isNotEmpty).map(ElasticsearchEntry::toEntity).forEach(entities::add);
}
use of org.elasticsearch.client.RestHighLevelClient in project logging-log4j2 by apache.
the class LogstashIT method test_newlines.
@Test
void test_newlines() throws IOException {
// Create two log events containing new lines.
final Level level = Level.DEBUG;
final String loggerFqcn = "f.q.c.n";
final String loggerName = "A";
final SimpleMessage message1 = new SimpleMessage("line1\nline2\r\nline3");
final long instantMillis1 = Instant.EPOCH.toEpochMilli();
final LogEvent logEvent1 = Log4jLogEvent.newBuilder().setLoggerName(loggerName).setLoggerFqcn(loggerFqcn).setLevel(level).setMessage(message1).setTimeMillis(instantMillis1).build();
final SimpleMessage message2 = new SimpleMessage("line4\nline5\r\nline6");
final long instantMillis2 = instantMillis1 + Duration.ofDays(1).toMillis();
final LogEvent logEvent2 = Log4jLogEvent.newBuilder().setLoggerName(loggerName).setLoggerFqcn(loggerFqcn).setLevel(level).setMessage(message2).setTimeMillis(instantMillis2).build();
try (final RestHighLevelClient client = createClient()) {
final Appender appender = createStartedAppender(JSON_TEMPLATE_GELF_LAYOUT, MavenHardcodedConstants.LS_GELF_INPUT_PORT);
try {
// Append the event.
LOGGER.info("appending events");
appender.append(logEvent1);
appender.append(logEvent2);
LOGGER.info("completed appending events");
// Wait the message to arrive.
Awaitility.await().atMost(Duration.ofSeconds(60)).pollDelay(Duration.ofSeconds(2)).until(() -> queryDocumentCount(client) == 2);
// Verify indexed messages.
final Set<String> expectedMessages = Stream.of(logEvent1, logEvent2).map(LogstashIT::expectedLogstashMessageField).collect(Collectors.toSet());
final Set<String> actualMessages = queryDocuments(client).stream().map(source -> (String) source.get(ES_INDEX_MESSAGE_FIELD_NAME)).filter(Objects::nonNull).collect(Collectors.toSet());
Assertions.assertThat(actualMessages).isEqualTo(expectedMessages);
} finally {
appender.stop();
}
}
}
use of org.elasticsearch.client.RestHighLevelClient in project presto by prestodb.
the class ElasticsearchClient method createClient.
private static RestHighLevelClient createClient(ElasticsearchConfig config, Optional<AwsSecurityConfig> awsSecurityConfig) {
RestClientBuilder builder = RestClient.builder(new HttpHost(config.getHost(), config.getPort(), config.isTlsEnabled() ? "https" : "http")).setMaxRetryTimeoutMillis((int) config.getMaxRetryTime().toMillis());
builder.setHttpClientConfigCallback(ignored -> {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(toIntExact(config.getConnectTimeout().toMillis())).setSocketTimeout(toIntExact(config.getRequestTimeout().toMillis())).build();
IOReactorConfig reactorConfig = IOReactorConfig.custom().setIoThreadCount(config.getHttpThreadCount()).build();
// the client builder passed to the call-back is configured to use system properties, which makes it
// impossible to configure concurrency settings, so we need to build a new one from scratch
HttpAsyncClientBuilder clientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfig).setDefaultIOReactorConfig(reactorConfig).setMaxConnPerRoute(config.getMaxHttpConnections()).setMaxConnTotal(config.getMaxHttpConnections());
if (config.isTlsEnabled()) {
buildSslContext(config.getKeystorePath(), config.getKeystorePassword(), config.getTrustStorePath(), config.getTruststorePassword()).ifPresent(clientBuilder::setSSLContext);
if (config.isVerifyHostnames()) {
clientBuilder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
}
}
awsSecurityConfig.ifPresent(securityConfig -> clientBuilder.addInterceptorLast(new AwsRequestSigner(securityConfig.getRegion(), getAwsCredentialsProvider(securityConfig))));
return clientBuilder;
});
return new RestHighLevelClient(builder);
}
use of org.elasticsearch.client.RestHighLevelClient in project flink by apache.
the class ElasticsearchSinkBaseITCase method createRestHighLevelClient.
private RestHighLevelClient createRestHighLevelClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(ELASTICSEARCH_USER, ELASTICSEARCH_PASSWORD));
return new RestHighLevelClient(RestClient.builder(HttpHost.create(getElasticsearchHttpHostAddress())).setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)));
}
Aggregations