Search in sources :

Example 6 with BulkResponse

use of org.opensearch.action.bulk.BulkResponse in project fess by codelibs.

the class SearchHelper method bulkUpdate.

public boolean bulkUpdate(final Consumer<BulkRequestBuilder> consumer) {
    final BulkRequestBuilder builder = ComponentUtil.getSearchEngineClient().prepareBulk();
    consumer.accept(builder);
    try {
        final BulkResponse response = builder.execute().get();
        if (response.hasFailures()) {
            throw new SearchEngineClientException(response.buildFailureMessage());
        }
        return true;
    } catch (InterruptedException | ExecutionException e) {
        throw new SearchEngineClientException("Failed to update bulk data.", e);
    }
}
Also used : SearchEngineClientException(org.codelibs.fess.es.client.SearchEngineClientException) BulkResponse(org.opensearch.action.bulk.BulkResponse) BulkRequestBuilder(org.opensearch.action.bulk.BulkRequestBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with BulkResponse

use of org.opensearch.action.bulk.BulkResponse in project fess by codelibs.

the class ScoreBooster method flush.

protected void flush() {
    if (bulkRequestBuilder != null) {
        final BulkResponse response = bulkRequestBuilder.execute().actionGet(requestTimeout);
        if (response.hasFailures()) {
            logger.warn("Failed to update scores: {}", response.buildFailureMessage());
        }
        bulkRequestBuilder = null;
    }
}
Also used : BulkResponse(org.opensearch.action.bulk.BulkResponse)

Example 8 with BulkResponse

use of org.opensearch.action.bulk.BulkResponse in project fess by codelibs.

the class EsAbstractBehavior method delegateBatchRequest.

protected <BUILDER> int[] delegateBatchRequest(final List<? extends Entity> entityList, Function<EsAbstractEntity, BUILDER> call) {
    @SuppressWarnings("unchecked") final BulkList<? extends Entity, BUILDER> bulkList = (BulkList<? extends Entity, BUILDER>) entityList;
    final RequestOptionCall<BUILDER> builderEntityCall = bulkList.getEntityCall();
    final BulkRequestBuilder bulkBuilder = client.prepareBulk();
    for (final Entity entity : entityList) {
        final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
        BUILDER builder = call.apply(esEntity);
        if (builder instanceof IndexRequestBuilder) {
            if (builderEntityCall != null) {
                builderEntityCall.callback(builder);
            }
            bulkBuilder.add((IndexRequestBuilder) builder);
        } else if (builder instanceof UpdateRequestBuilder) {
            if (builderEntityCall != null) {
                builderEntityCall.callback(builder);
            }
            bulkBuilder.add((UpdateRequestBuilder) builder);
        } else if (builder instanceof DeleteRequestBuilder) {
            if (builderEntityCall != null) {
                builderEntityCall.callback(builder);
            }
            bulkBuilder.add((DeleteRequestBuilder) builder);
        }
    }
    final RequestOptionCall<BulkRequestBuilder> builderCall = bulkList.getCall();
    if (builderCall != null) {
        builderCall.callback(bulkBuilder);
    }
    final BulkResponse response = bulkBuilder.execute().actionGet(bulkTimeout);
    final BulkItemResponse[] itemResponses = response.getItems();
    if (itemResponses.length != entityList.size()) {
        throw new IllegalStateException("Invalid response size: " + itemResponses.length + " != " + entityList.size());
    }
    final int[] results = new int[itemResponses.length];
    for (int i = 0; i < itemResponses.length; i++) {
        final BulkItemResponse itemResponse = itemResponses[i];
        final Entity entity = entityList.get(i);
        if (entity instanceof EsAbstractEntity) {
            ((EsAbstractEntity) entity).asDocMeta().id(itemResponse.getId());
        }
        results[i] = itemResponse.isFailed() ? 0 : 1;
    }
    return results;
}
Also used : DeleteRequestBuilder(org.opensearch.action.delete.DeleteRequestBuilder) Entity(org.dbflute.Entity) UpdateRequestBuilder(org.opensearch.action.update.UpdateRequestBuilder) BulkItemResponse(org.opensearch.action.bulk.BulkItemResponse) BulkResponse(org.opensearch.action.bulk.BulkResponse) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) BulkRequestBuilder(org.opensearch.action.bulk.BulkRequestBuilder)

Aggregations

BulkResponse (org.opensearch.action.bulk.BulkResponse)8 BulkRequestBuilder (org.opensearch.action.bulk.BulkRequestBuilder)7 Entity (org.dbflute.Entity)3 IllegalBehaviorStateException (org.dbflute.exception.IllegalBehaviorStateException)3 BulkItemResponse (org.opensearch.action.bulk.BulkItemResponse)3 DeleteRequestBuilder (org.opensearch.action.delete.DeleteRequestBuilder)3 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)3 SearchRequestBuilder (org.opensearch.action.search.SearchRequestBuilder)3 SearchResponse (org.opensearch.action.search.SearchResponse)3 UpdateRequestBuilder (org.opensearch.action.update.UpdateRequestBuilder)3 SearchHit (org.opensearch.search.SearchHit)3 SearchHits (org.opensearch.search.SearchHits)3 ExecutionException (java.util.concurrent.ExecutionException)1 SearchEngineClientException (org.codelibs.fess.es.client.SearchEngineClientException)1