use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project pancm_project by xuwujing.
the class IpHandler method init.
/*
* 初始化服务
*/
private static RestHighLevelClient init() {
if (client == null) {
synchronized (EsUtil.class) {
if (client == null) {
RestClientBuilder restClientBuilder = RestClient.builder(httpHosts);
client = new RestHighLevelClient(restClientBuilder);
}
}
}
return client;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentConfiguration method get.
@Override
public ElasticsearchDocumentCollectionManagerFactory get(Settings settings) throws NullPointerException {
requireNonNull(settings, "settings is required");
Map<String, String> configurations = new HashMap<>();
settings.forEach((key, value) -> configurations.put(key, value.toString()));
configurations.keySet().stream().filter(k -> k.startsWith(HOST_PREFIX)).sorted().map(h -> ElasticsearchAddress.of(configurations.get(h), DEFAULT_PORT)).map(ElasticsearchAddress::toHttpHost).forEach(httpHosts::add);
RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()]));
builder.setDefaultHeaders(headers.stream().toArray(Header[]::new));
String maxRetry = configurations.get("elasticsearch-maxRetryTimeoutMillis");
if (maxRetry != null) {
maxRetryTimoutMillis = Integer.valueOf(maxRetry);
}
builder.setMaxRetryTimeoutMillis(maxRetryTimoutMillis);
RestHighLevelClient client = new RestHighLevelClient(builder);
return new ElasticsearchDocumentCollectionManagerFactory(client);
}
use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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();
}
}
}
Aggregations