Search in sources :

Example 36 with RestHighLevelClient

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;
}
Also used : RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 37 with RestHighLevelClient

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);
}
Also used : Header(org.apache.http.Header) HashMap(java.util.HashMap) HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 38 with RestHighLevelClient

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);
}
Also used : RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 39 with RestHighLevelClient

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);
}
Also used : Document(org.jnosql.diana.api.document.Document) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) IOException(java.io.IOException) HashMap(java.util.HashMap) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) SearchRequest(org.elasticsearch.action.search.SearchRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) StreamSupport(java.util.stream.StreamSupport) Collections.singletonMap(java.util.Collections.singletonMap) ValueUtil(org.jnosql.diana.driver.ValueUtil) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest)

Example 40 with RestHighLevelClient

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();
        }
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) SocketAppender(org.apache.logging.log4j.core.appender.SocketAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Level(org.apache.logging.log4j.Level) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Test(org.junit.jupiter.api.Test)

Aggregations

RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)56 HttpHost (org.apache.http.HttpHost)22 RestClientBuilder (org.elasticsearch.client.RestClientBuilder)19 IOException (java.io.IOException)12 RestClient (org.elasticsearch.client.RestClient)11 HashMap (java.util.HashMap)9 IndexRequest (org.elasticsearch.action.index.IndexRequest)8 Test (org.junit.jupiter.api.Test)7 SearchRequest (org.elasticsearch.action.search.SearchRequest)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 RequestOptions (org.elasticsearch.client.RequestOptions)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 CredentialsProvider (org.apache.http.client.CredentialsProvider)5 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)5 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)5 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)5 Test (org.junit.Test)5 TableEnvironment (org.apache.flink.table.api.TableEnvironment)4