use of org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder in project core-ng-project by neowu.
the class ElasticSearchTypeImpl method deleteByQuery.
@Override
public long deleteByQuery(DeleteByQueryRequest request) {
if (request.query == null)
throw Exceptions.error("request.query must not be null");
StopWatch watch = new StopWatch();
String index = request.index == null ? this.index : request.index;
long esTookTime = 0;
long deleted = 0;
try {
DeleteByQueryRequestBuilder builder = DeleteByQueryAction.INSTANCE.newRequestBuilder(client());
BulkByScrollResponse response = builder.filter(request.query).source(index).get();
esTookTime = response.getTook().nanos();
deleted = response.getDeleted();
return deleted;
} catch (ElasticsearchException e) {
// due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
throw new SearchException(e);
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("elasticsearch", elapsedTime, 0, (int) deleted);
logger.debug("deleteByQuery, index={}, type={}, deleted={}, esTookTime={}, elapsedTime={}", index, type, deleted, esTookTime, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder in project elasticsearch-indexing-proxy by codelibs.
the class RequestSender method processDeleteByQueryRequest.
private void processDeleteByQueryRequest(final StreamInput streamInput) throws IOException {
final DeleteByQueryRequestBuilder builder = RequestUtils.createDeleteByQueryRequest(client, streamInput, index);
executeDeleteByQueryRequest(streamInput, builder);
}
use of org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder in project elasticsearch-indexing-proxy by codelibs.
the class RequestUtils method createDeleteByQueryRequest.
public static DeleteByQueryRequestBuilder createDeleteByQueryRequest(final Client client, final StreamInput streamInput, final String index) throws IOException {
final DeleteByQueryRequestBuilder builder = client.prepareExecute(DeleteByQueryAction.INSTANCE);
final DeleteByQueryRequest request = builder.request();
request.readFrom(streamInput);
if (index != null) {
request.indices(index);
}
return builder;
}
use of org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder in project vertigo by KleeGroup.
the class ESStatement method remove.
/**
* Supprime des documents.
* @param query Requete de filtrage des documents à supprimer
*/
void remove(final ListFilter query) {
Assertion.checkNotNull(query);
// -----
try {
final QueryBuilder queryBuilder = ESSearchRequestBuilder.translateToQueryBuilder(query);
final DeleteByQueryRequestBuilder deleteByQueryAction = DeleteByQueryAction.INSTANCE.newRequestBuilder(esClient).filter(queryBuilder);
deleteByQueryAction.source().setIndices(indexName).setTypes(typeName);
final BulkByScrollResponse response = deleteByQueryAction.get();
final long deleted = response.getDeleted();
LOGGER.debug("Removed {0} elements", deleted);
} catch (final SearchPhaseExecutionException e) {
final VUserException vue = new VUserException(SearchResource.DYNAMO_SEARCH_QUERY_SYNTAX_ERROR);
vue.initCause(e);
throw vue;
}
}
Aggregations