Search in sources :

Example 1 with DeleteResponse

use of co.elastic.clients.elasticsearch.core.DeleteResponse in project syncope by apache.

the class ElasticsearchIndexManager method after.

@TransactionalEventListener
public void after(final AnyDeletedEvent event) throws IOException {
    LOG.debug("About to delete index for {}[{}]", event.getAnyTypeKind(), event.getAnyKey());
    DeleteRequest request = new DeleteRequest.Builder().index(ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), event.getAnyTypeKind())).id(event.getAnyKey()).build();
    DeleteResponse response = client.delete(request);
    LOG.debug("Index successfully deleted for {}[{}]: {}", event.getAnyTypeKind(), event.getAnyKey(), response);
}
Also used : DeleteResponse(co.elastic.clients.elasticsearch.core.DeleteResponse) DeleteRequest(co.elastic.clients.elasticsearch.core.DeleteRequest) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener)

Example 2 with DeleteResponse

use of co.elastic.clients.elasticsearch.core.DeleteResponse in project core-ng-project by neowu.

the class ElasticSearchTypeImpl method delete.

@Override
public boolean delete(DeleteRequest request) {
    var watch = new StopWatch();
    String index = request.index == null ? this.index : request.index;
    boolean deleted = false;
    try {
        DeleteResponse response = elasticSearch.client.delete(builder -> builder.index(index).id(request.id));
        deleted = response.result() == Result.Deleted;
        return deleted;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (ElasticsearchException e) {
        throw elasticSearch.searchException(e);
    } finally {
        long elapsed = watch.elapsed();
        ActionLogContext.track("elasticsearch", elapsed, 0, deleted ? 1 : 0);
        logger.debug("delete, index={}, id={}, elapsed={}", index, request.id, elapsed);
        checkSlowOperation(elapsed);
    }
}
Also used : DeleteResponse(co.elastic.clients.elasticsearch.core.DeleteResponse) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ElasticsearchException(co.elastic.clients.elasticsearch._types.ElasticsearchException) StopWatch(core.framework.util.StopWatch)

Aggregations

DeleteResponse (co.elastic.clients.elasticsearch.core.DeleteResponse)2 ElasticsearchException (co.elastic.clients.elasticsearch._types.ElasticsearchException)1 DeleteRequest (co.elastic.clients.elasticsearch.core.DeleteRequest)1 StopWatch (core.framework.util.StopWatch)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 TransactionalEventListener (org.springframework.transaction.event.TransactionalEventListener)1