Search in sources :

Example 31 with RestHighLevelClient

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project warn-report by saaavsaaa.

the class ElasticClient method get.

@Test
public void get() throws IOException {
    RestClientBuilder builder = RestClient.builder(new HttpHost("sl010a-analysisdb1", 9200, "https"), new HttpHost("sl010a-analysisdb2", 9200, "https"), new HttpHost("sl010a-analysisdb3", 9200, "https"));
    Header[] defaultHeaders = new Header[] { new BasicHeader("Authorization", "Basic YWRtaW46YWRtaW4=") };
    builder.setDefaultHeaders(defaultHeaders);
    RestClient restClient = builder.build();
    RestHighLevelClient client = new RestHighLevelClient(restClient);
    GetRequest getRequest = new GetRequest("test-index", "test-all", "26269");
    GetResponse getResponse = client.get(getRequest);
    System.out.println(getResponse.getSourceAsString());
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HttpHost(org.apache.http.HttpHost) GetRequest(org.elasticsearch.action.get.GetRequest) RestClient(org.elasticsearch.client.RestClient) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) GetResponse(org.elasticsearch.action.get.GetResponse) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Example 32 with RestHighLevelClient

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project nutch by apache.

the class ElasticIndexWriter method makeClient.

/**
 * Generates a RestHighLevelClient with the hosts given
 * @param parameters implementation specific {@link org.apache.nutch.indexer.IndexWriterParams}
 * @return an initialized {@link org.elasticsearch.client.RestHighLevelClient}
 * @throws IOException if there is an error reading the
 * {@link org.apache.nutch.indexer.IndexWriterParams}
 */
protected RestHighLevelClient makeClient(IndexWriterParams parameters) throws IOException {
    hosts = parameters.getStrings(ElasticConstants.HOSTS);
    port = parameters.getInt(ElasticConstants.PORT, DEFAULT_PORT);
    scheme = parameters.get(ElasticConstants.SCHEME, HttpHost.DEFAULT_SCHEME_NAME);
    auth = parameters.getBoolean(ElasticConstants.USE_AUTH, false);
    user = parameters.get(ElasticConstants.USER, DEFAULT_USER);
    password = parameters.get(ElasticConstants.PASSWORD, "");
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    RestHighLevelClient client = null;
    if (hosts != null && port > 1) {
        HttpHost[] hostsList = new HttpHost[hosts.length];
        int i = 0;
        for (String host : hosts) {
            hostsList[i++] = new HttpHost(host, port, scheme);
        }
        RestClientBuilder restClientBuilder = RestClient.builder(hostsList);
        if (auth) {
            restClientBuilder.setHttpClientConfigCallback(new HttpClientConfigCallback() {

                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder arg0) {
                    return arg0.setDefaultCredentialsProvider(credentialsProvider);
                }
            });
        }
        client = new RestHighLevelClient(restClientBuilder);
    } else {
        throw new IOException("ElasticRestClient initialization Failed!!!\\n\\nPlease Provide the hosts");
    }
    return client;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IOException(java.io.IOException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) HttpHost(org.apache.http.HttpHost) HttpClientConfigCallback(org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback)

Example 33 with RestHighLevelClient

use of org.graylog.shaded.elasticsearch7.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 34 with RestHighLevelClient

use of org.graylog.shaded.elasticsearch7.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 35 with RestHighLevelClient

use of org.graylog.shaded.elasticsearch7.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)

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