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());
}
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;
}
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);
}
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);
}
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);
}
Aggregations