Search in sources :

Example 11 with BulkByScrollResponse

use of org.elasticsearch.index.reindex.BulkByScrollResponse in project incubator-skywalking by apache.

the class ServiceAlarmEsPersistenceDAO method deleteHistory.

@Override
public void deleteHistory(Long startTimestamp, Long endTimestamp) {
    long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp);
    long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp);
    BulkByScrollResponse response = getClient().prepareDelete(QueryBuilders.rangeQuery(ServiceAlarmTable.COLUMN_LAST_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket), ServiceAlarmTable.TABLE).get();
    long deleted = response.getDeleted();
    logger.info("Delete {} rows history from {} index.", deleted, ServiceAlarmTable.TABLE);
}
Also used : BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse)

Example 12 with BulkByScrollResponse

use of org.elasticsearch.index.reindex.BulkByScrollResponse in project incubator-skywalking by apache.

the class SegmentEsPersistenceDAO method deleteHistory.

@Override
public void deleteHistory(Long startTimestamp, Long endTimestamp) {
    long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp);
    long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp);
    BulkByScrollResponse response = getClient().prepareDelete(QueryBuilders.rangeQuery(SegmentTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket), SegmentTable.TABLE).get();
    long deleted = response.getDeleted();
    logger.info("Delete {} rows history from {} index.", deleted, SegmentTable.TABLE);
}
Also used : BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse)

Example 13 with BulkByScrollResponse

use of org.elasticsearch.index.reindex.BulkByScrollResponse 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 14 with BulkByScrollResponse

use of org.elasticsearch.index.reindex.BulkByScrollResponse in project vorto by eclipse.

the class ElasticSearchService method deleteByQuery.

private void deleteByQuery(String index, QueryBuilder query) {
    logger.info(String.format("Trying to delete all models in index '%s'", index));
    DeleteByQueryRequest request = new DeleteByQueryRequest(index);
    request.setQuery(query);
    try {
        BulkByScrollResponse bulkResponse = client.deleteByQuery(request, RequestOptions.DEFAULT);
        logger.info(String.format("Deleted %d models in the index '%s'", bulkResponse.getTotal(), index));
    } catch (IOException e) {
        throw new IndexingException(String.format("Error deleting all models in the '%s' index.", index), e);
    }
}
Also used : DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) IOException(java.io.IOException) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse)

Example 15 with BulkByScrollResponse

use of org.elasticsearch.index.reindex.BulkByScrollResponse in project incubator-skywalking by apache.

the class InstanceAlarmEsPersistenceDAO method deleteHistory.

@Override
public void deleteHistory(Long startTimestamp, Long endTimestamp) {
    long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp);
    long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp);
    BulkByScrollResponse response = getClient().prepareDelete(QueryBuilders.rangeQuery(InstanceAlarmTable.COLUMN_LAST_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket), InstanceAlarmTable.TABLE).get();
    long deleted = response.getDeleted();
    logger.info("Delete {} rows history from {} index.", deleted, InstanceAlarmTable.TABLE);
}
Also used : BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse)

Aggregations

BulkByScrollResponse (org.elasticsearch.index.reindex.BulkByScrollResponse)28 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)6 DeleteByQueryRequest (org.elasticsearch.index.reindex.DeleteByQueryRequest)6 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)5 TimeValue (org.elasticsearch.common.unit.TimeValue)4 UpdateByQueryRequest (org.elasticsearch.index.reindex.UpdateByQueryRequest)4 IOException (java.io.IOException)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 DeleteByQueryRequestBuilder (org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder)2 ReindexRequest (org.elasticsearch.index.reindex.ReindexRequest)2 EsQueryBuilder (com.b2international.index.es.query.EsQueryBuilder)1 SearchException (core.framework.search.SearchException)1 StopWatch (core.framework.util.StopWatch)1 VUserException (io.vertigo.lang.VUserException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GoraException (org.apache.gora.util.GoraException)1 ActionResponse (org.elasticsearch.action.ActionResponse)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1