Search in sources :

Example 1 with DeleteByQueryRequestBuilder

use of org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method unindexEntity.

@Override
public void unindexEntity(final String href) throws CalFacadeException {
    try {
        final DeleteByQueryRequestBuilder dqrb = getClient().prepareDeleteByQuery(targetIndex);
        dqrb.setQuery(QueryBuilders.termQuery(ESQueryFilter.hrefJname, href));
        /*final DeleteByQueryResponse resp = */
        dqrb.execute().actionGet();
        markUpdated(null);
    // TODO check response?
    } catch (final ElasticsearchException ese) {
        // Failed somehow
        error(ese);
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        error(t);
        throw new CalFacadeException(t);
    } finally {
        lastIndexTime = System.currentTimeMillis();
    }
}
Also used : DeleteByQueryRequestBuilder(org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with DeleteByQueryRequestBuilder

use of org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method deleteEvent.

private boolean deleteEvent(final String href) throws CalFacadeException {
    final DeleteByQueryRequestBuilder delQreq = getClient().prepareDeleteByQuery(targetIndex).setTypes(docTypeEvent, docTypePoll);
    final ESQueryFilter esq = getFilters(null);
    final FilterBuilder fb = esq.addTerm(PropertyInfoIndex.HREF, href);
    delQreq.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), fb));
    final DeleteByQueryResponse delResp = delQreq.execute().actionGet();
    boolean ok = true;
    for (final IndexDeleteByQueryResponse idqr : delResp.getIndices().values()) {
        if (idqr.getFailedShards() > 0) {
            warn("Failing shards for delete href: " + href + " index: " + idqr.getIndex());
            ok = false;
        }
    }
    return ok;
}
Also used : DeleteByQueryResponse(org.elasticsearch.action.deletebyquery.DeleteByQueryResponse) IndexDeleteByQueryResponse(org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) DeleteByQueryRequestBuilder(org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder) IndexDeleteByQueryResponse(org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse)

Aggregations

DeleteByQueryRequestBuilder (org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 DeleteByQueryResponse (org.elasticsearch.action.deletebyquery.DeleteByQueryResponse)1 IndexDeleteByQueryResponse (org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse)1 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)1 TermFilterBuilder (org.elasticsearch.index.query.TermFilterBuilder)1