use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project hazelcast by hazelcast.
the class LocalElasticSourcesTest method when_readFromElasticSource_then_shouldCloseAllCreatedClients.
@Test
public void when_readFromElasticSource_then_shouldCloseAllCreatedClients() throws IOException {
indexDocument("my-index", of("name", "Frantisek"));
Pipeline p = Pipeline.create();
BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(() -> {
RestClientBuilder builder = spy(ElasticSupport.elasticClientSupplier().get());
when(builder.build()).thenAnswer(invocation -> {
Object result = invocation.callRealMethod();
RestClient elasticClient = (RestClient) spy(result);
ClientHolder.elasticClients.add(elasticClient);
return elasticClient;
});
return builder;
}).searchRequestFn(() -> new SearchRequest("my-index")).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
p.readFrom(source).writeTo(Sinks.logger());
submitJob(p);
for (RestClient elasticClient : ClientHolder.elasticClients) {
verify(elasticClient).close();
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project metron by apache.
the class ElasticsearchClientFactory method create.
/**
* Creates an Elasticsearch client from settings provided via the global config.
*
* @return new client
*/
public static ElasticsearchClient create(Map<String, Object> globalConfig) {
ElasticsearchClientConfig esClientConfig = new ElasticsearchClientConfig(getEsSettings(globalConfig));
HttpHost[] httpHosts = getHttpHosts(globalConfig, esClientConfig.getConnectionScheme());
RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setRequestConfigCallback(reqConfigBuilder -> {
// Modifies request config builder with connection and socket timeouts.
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/_timeouts.html
reqConfigBuilder.setConnectTimeout(esClientConfig.getConnectTimeoutMillis());
reqConfigBuilder.setSocketTimeout(esClientConfig.getSocketTimeoutMillis());
return reqConfigBuilder;
});
builder.setMaxRetryTimeoutMillis(esClientConfig.getMaxRetryTimeoutMillis());
builder.setHttpClientConfigCallback(clientBuilder -> {
clientBuilder.setDefaultIOReactorConfig(getIOReactorConfig(esClientConfig));
clientBuilder.setDefaultCredentialsProvider(getCredentialsProvider(esClientConfig));
clientBuilder.setSSLContext(getSSLContext(esClientConfig));
return clientBuilder;
});
RestClient lowLevelClient = builder.build();
RestHighLevelClient client = new RestHighLevelClient(lowLevelClient);
return new ElasticsearchClient(lowLevelClient, client);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient 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.RestClient in project pancm_project by xuwujing.
the class EsHighLevelCluster method setCool.
/**
* @return void
* @Author pancm
* @Description 设置该节点为冷节点
* @Date 2020/1/2
* @Param [index]
*/
public static void setCool(String index) throws IOException {
RestClient restClient = null;
try {
Objects.requireNonNull(index, "index is not null");
restClient = client.getLowLevelClient();
String source = "{\"index.routing.allocation.require.box_type\": \"%s\"}";
source = String.format(source, "cool");
HttpEntity entity = new NStringEntity(source, ContentType.APPLICATION_JSON);
restClient.performRequest("PUT", "/" + index + "/_settings", Collections.<String, String>emptyMap(), entity);
} catch (IOException e) {
throw e;
} finally {
if (restClient != null) {
restClient.close();
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project pancm_project by xuwujing.
the class EsHighLevelCluster method setAlias.
public void setAlias(String index, String aliasIndex) throws IOException {
RestClient restClient = null;
try {
Objects.requireNonNull(index, "index is not null");
restClient = client.getLowLevelClient();
String msg = "/" + index + "/_alias" + "/" + aliasIndex;
restClient.performRequest("PUT", msg);
} finally {
if (restClient != null) {
restClient.close();
}
}
}
Aggregations