Search in sources :

Example 1 with DeleteByQueryRequestBuilder

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);
    }
}
Also used : SearchException(core.framework.search.SearchException) DeleteByQueryRequestBuilder(org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) StopWatch(core.framework.util.StopWatch) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse)

Example 2 with DeleteByQueryRequestBuilder

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);
}
Also used : DeleteByQueryRequestBuilder(org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder)

Example 3 with DeleteByQueryRequestBuilder

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;
}
Also used : DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) DeleteByQueryRequestBuilder(org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder)

Example 4 with DeleteByQueryRequestBuilder

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;
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) DeleteByQueryRequestBuilder(org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse) VUserException(io.vertigo.lang.VUserException)

Aggregations

DeleteByQueryRequestBuilder (org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder)4 BulkByScrollResponse (org.elasticsearch.index.reindex.BulkByScrollResponse)2 SearchException (core.framework.search.SearchException)1 StopWatch (core.framework.util.StopWatch)1 VUserException (io.vertigo.lang.VUserException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 DeleteByQueryRequest (org.elasticsearch.index.reindex.DeleteByQueryRequest)1