use of core.framework.search.BulkDeleteRequest in project core-ng-project by neowu.
the class ElasticSearchTypeImpl method bulkDelete.
@Override
public void bulkDelete(BulkDeleteRequest request) {
var watch = new StopWatch();
if (request.ids == null || request.ids.isEmpty())
throw new Error("request.ids must not be empty");
String index = request.index == null ? this.index : request.index;
List<BulkOperation> operations = new ArrayList<>(request.ids.size());
for (String id : request.ids) {
operations.add(BulkOperation.of(builder -> builder.delete(r -> r.index(index).id(id))));
}
long esTook = 0;
try {
BulkResponse response = elasticSearch.client.bulk(builder -> builder.operations(operations));
// mills to nano
esTook = response.took() * 1_000_000;
validate(response);
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (ElasticsearchException e) {
throw elasticSearch.searchException(e);
} finally {
long elapsed = watch.elapsed();
int size = request.ids.size();
ActionLogContext.track("elasticsearch", elapsed, 0, size);
logger.debug("bulkDelete, index={}, ids={}, size={}, esTook={}, elapsed={}", index, request.ids, size, esTook, elapsed);
checkSlowOperation(elapsed);
}
}
Aggregations