use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project ranger by apache.
the class ElasticSearchAuditDestination method newClient.
private RestHighLevelClient newClient() {
try {
if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password) && password.contains("keytab") && new File(password).exists()) {
subject = CredentialsProviderUtil.login(user, password);
}
RestClientBuilder restClientBuilder = getRestClientBuilder(hosts, protocol, user, password, port);
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
if (LOG.isDebugEnabled()) {
LOG.debug("Initialized client");
}
boolean exits = false;
try {
exits = restHighLevelClient.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
} catch (Exception e) {
LOG.warn("Error validating index " + this.index);
}
if (exits) {
if (LOG.isDebugEnabled()) {
LOG.debug("Index exists");
}
} else {
LOG.info("Index does not exist");
}
return restHighLevelClient;
} catch (Throwable t) {
lastLoggedAt.updateAndGet(lastLoggedAt -> {
long now = System.currentTimeMillis();
long elapsed = now - lastLoggedAt;
if (elapsed > TimeUnit.MINUTES.toMillis(1)) {
LOG.error("Can't connect to ElasticSearch server: " + connectionString(), t);
return now;
} else {
return lastLoggedAt;
}
});
return null;
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project pancm_project by xuwujing.
the class EsScriptSearchTest 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 elasticsearch by elastic.
the class DeleteDocumentationIT method testDelete.
/**
* This test documents docs/java-rest/high-level/document/delete.asciidoc
*/
public void testDelete() throws IOException {
RestHighLevelClient client = highLevelClient();
// tag::delete-request[]
DeleteRequest request = new DeleteRequest(// <1>
"index", // <2>
"type", // <3>
"id");
// end::delete-request[]
// tag::delete-request-props[]
// <1>
request.timeout(TimeValue.timeValueSeconds(1));
// <2>
request.timeout("1s");
// <3>
request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
// <4>
request.setRefreshPolicy("wait_for");
// <5>
request.version(2);
// <6>
request.versionType(VersionType.EXTERNAL);
// end::delete-request-props[]
// tag::delete-execute[]
DeleteResponse response = client.delete(request);
try {
// tag::delete-notfound[]
if (response.getResult().equals(DocWriteResponse.Result.NOT_FOUND)) {
// <1>
throw new Exception("Can't find document to be removed");
}
// end::delete-notfound[]
} catch (Exception ignored) {
}
// tag::delete-execute-async[]
client.deleteAsync(request, new ActionListener<DeleteResponse>() {
@Override
public void onResponse(DeleteResponse deleteResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
});
// tag::delete-conflict[]
try {
client.delete(request);
} catch (ElasticsearchException exception) {
if (exception.status().equals(RestStatus.CONFLICT)) {
// <1>
}
}
// end::delete-conflict[]
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project elastest-torm by elastest.
the class ElasticsearchService method init.
@PostConstruct
private void init() {
URL url;
try {
url = new URL(this.esApiUrl);
this.host = url.getHost();
this.port = url.getPort();
logger.debug("Elasticsearch API host: {} / port: {}", this.host, this.port);
this.esClient = new RestHighLevelClient(RestClient.builder(new HttpHost(this.host, this.port, "http")));
} catch (MalformedURLException e) {
logger.error("Cannot get Elasticsearch url by given: {}", this.esApiUrl);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project hazelcast by hazelcast.
the class ElasticSinkBuilder method build.
/**
* Create a sink that writes data into Elasticsearch based on this builder configuration
*/
@Nonnull
public Sink<T> build() {
requireNonNull(clientFn, "clientFn is not set");
requireNonNull(mapToRequestFn, "mapToRequestFn is not set");
return SinkBuilder.sinkBuilder(DEFAULT_NAME, ctx -> new BulkContext(new RestHighLevelClient(clientFn.get()), bulkRequestFn, optionsFn, retries, ctx.logger())).<T>receiveFn((bulkContext, item) -> bulkContext.add(mapToRequestFn.apply(item))).flushFn(BulkContext::flush).destroyFn(BulkContext::close).preferredLocalParallelism(DEFAULT_LOCAL_PARALLELISM).build();
}
Aggregations