Search in sources :

Example 41 with RestHighLevelClient

use of org.elasticsearch.client.RestHighLevelClient in project pancm_project by xuwujing.

the class EsParticipleSearchTest method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 42 with RestHighLevelClient

use of org.elasticsearch.client.RestHighLevelClient in project pancm_project by xuwujing.

the class EsAggregationSearchTest method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 43 with RestHighLevelClient

use of org.elasticsearch.client.RestHighLevelClient in project pancm_project by xuwujing.

the class EsAggregationSearchTest2 method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 44 with RestHighLevelClient

use of 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 45 with RestHighLevelClient

use of 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)

Aggregations

RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)61 HttpHost (org.apache.http.HttpHost)23 RestClientBuilder (org.elasticsearch.client.RestClientBuilder)21 IOException (java.io.IOException)14 RestClient (org.elasticsearch.client.RestClient)13 HashMap (java.util.HashMap)10 IndexRequest (org.elasticsearch.action.index.IndexRequest)8 RequestOptions (org.elasticsearch.client.RequestOptions)7 Test (org.junit.jupiter.api.Test)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)6 SearchRequest (org.elasticsearch.action.search.SearchRequest)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)5 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)5 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)5 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)5