Search in sources :

Example 1 with BulkProcessor

use of org.elasticsearch.action.bulk.BulkProcessor in project samza by apache.

the class BulkProcessorFactory method getBulkProcessor.

public BulkProcessor getBulkProcessor(Client client, BulkProcessor.Listener listener) {
    BulkProcessor.Builder builder = BulkProcessor.builder(client, listener);
    // Concurrent requests set to 0 to ensure ordering of documents is maintained in batches.
    // This also means BulkProcessor#flush() is blocking as is also required.
    builder.setConcurrentRequests(0);
    if (config.getBulkFlushMaxActions().isPresent()) {
        builder.setBulkActions(config.getBulkFlushMaxActions().get());
    }
    if (config.getBulkFlushMaxSizeMB().isPresent()) {
        builder.setBulkSize(new ByteSizeValue(config.getBulkFlushMaxSizeMB().get(), ByteSizeUnit.MB));
    }
    if (config.getBulkFlushIntervalMS().isPresent()) {
        builder.setFlushInterval(TimeValue.timeValueMillis(config.getBulkFlushIntervalMS().get()));
    }
    return builder.build();
}
Also used : BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 2 with BulkProcessor

use of org.elasticsearch.action.bulk.BulkProcessor in project incubator-sdap-mudrod by apache.

the class ESDriver method createBulkProcessor.

public void createBulkProcessor() {
    LOG.debug("Creating BulkProcessor with maxBulkDocs={}, maxBulkLength={}", 1000, 2500500);
    setBulkProcessor(BulkProcessor.builder(getClient(), new BulkProcessor.Listener() {

        @Override
        public void beforeBulk(long executionId, BulkRequest request) {
            LOG.debug("ESDriver#createBulkProcessor @Override #beforeBulk is not implemented yet!");
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
            LOG.debug("ESDriver#createBulkProcessor @Override #afterBulk is not implemented yet!");
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
            LOG.error("Bulk request has failed!");
            throw new RuntimeException("Caught exception in bulk: " + request.getDescription() + ", failure: " + failure, failure);
        }
    }).setBulkActions(1000).setBulkSize(new ByteSizeValue(2500500, ByteSizeUnit.GB)).setBackoffPolicy(BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(100), 10)).setConcurrentRequests(1).build());
}
Also used : BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 3 with BulkProcessor

use of org.elasticsearch.action.bulk.BulkProcessor in project flink by apache.

the class ElasticsearchSinkBase method buildBulkProcessor.

/**
	 * Build the {@link BulkProcessor}.
	 *
	 * Note: this is exposed for testing purposes.
	 */
protected BulkProcessor buildBulkProcessor(BulkProcessor.Listener listener) {
    checkNotNull(listener);
    BulkProcessor.Builder bulkProcessorBuilder = BulkProcessor.builder(client, listener);
    // This makes flush() blocking
    bulkProcessorBuilder.setConcurrentRequests(0);
    if (bulkProcessorFlushMaxActions != null) {
        bulkProcessorBuilder.setBulkActions(bulkProcessorFlushMaxActions);
    }
    if (bulkProcessorFlushMaxSizeMb != null) {
        bulkProcessorBuilder.setBulkSize(new ByteSizeValue(bulkProcessorFlushMaxSizeMb, ByteSizeUnit.MB));
    }
    if (bulkProcessorFlushIntervalMillis != null) {
        bulkProcessorBuilder.setFlushInterval(TimeValue.timeValueMillis(bulkProcessorFlushIntervalMillis));
    }
    // if backoff retrying is disabled, bulkProcessorFlushBackoffPolicy will be null
    callBridge.configureBulkProcessorBackoff(bulkProcessorBuilder, bulkProcessorFlushBackoffPolicy);
    return bulkProcessorBuilder.build();
}
Also used : BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 4 with BulkProcessor

use of org.elasticsearch.action.bulk.BulkProcessor in project molgenis by molgenis.

the class ClientFacade method processDocumentActions.

public void processDocumentActions(Stream<DocumentAction> documentActions) {
    LOG.trace("Processing document actions ...");
    BulkProcessor bulkProcessor = bulkProcessorFactory.create(client);
    try {
        documentActions.forEachOrdered(documentAction -> {
            DocWriteRequest docWriteRequest = toDocWriteRequest(documentAction);
            bulkProcessor.add(docWriteRequest);
        });
    } finally {
        waitForCompletion(bulkProcessor);
        LOG.debug("Processed document actions.");
    }
}
Also used : BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) DocWriteRequest(org.elasticsearch.action.DocWriteRequest)

Example 5 with BulkProcessor

use of org.elasticsearch.action.bulk.BulkProcessor in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method reindex.

private void reindex(final ReindexResponse resp, final String indexName, final String docType) {
    // Only retrieve masters - we'll query for the overrides
    final QueryBuilder qb = getFilters(RecurringRetrievalMode.entityOnly).getAllForReindex(docType);
    // 1 minute
    final int timeoutMillis = 60000;
    final TimeValue tv = new TimeValue(timeoutMillis);
    final int batchSize = 100;
    final Client cl = getClient(resp);
    if (cl == null) {
        return;
    }
    checkUidsMap();
    // Start with default index as source
    targetIndex = Util.buildPath(false, idxpars.getUserIndexName());
    final BulkProcessor bulkProcessor = BulkProcessor.builder(cl, new BulkListener()).setBulkActions(batchSize).setConcurrentRequests(3).setFlushInterval(tv).build();
    SearchResponse scrollResp = cl.prepareSearch(targetIndex).setSearchType(SearchType.SCAN).setScroll(tv).setQuery(qb).setSize(batchSize).execute().actionGet();
    // Switch to new index
    targetIndex = indexName;
    // Scroll until no hits are returned
    while (true) {
        for (final SearchHit hit : scrollResp.getHits().getHits()) {
            final String dtype = hit.getType();
            resp.incProcessed();
            if ((resp.getProcessed() % 250) == 0) {
                info("processed " + docType + ": " + resp.getProcessed());
            }
            if (dtype.equals(docTypeUpdateTracker)) {
                continue;
            }
            resp.getStats().inc(docToType.getOrDefault(dtype, unreachableEntities));
            final ReindexResponse.Failure hitResp = new ReindexResponse.Failure();
            final Object entity = makeEntity(hitResp, hit, null);
            if (entity == null) {
                warn("Unable to build entity " + hit.sourceAsString());
                resp.incTotalFailed();
                if (resp.getTotalFailed() < 50) {
                    resp.addFailure(hitResp);
                }
                continue;
            }
            if (entity instanceof BwShareableDbentity) {
                final BwShareableDbentity ent = (BwShareableDbentity) entity;
                try {
                    principal = BwPrincipal.makePrincipal(ent.getOwnerHref());
                } catch (final CalFacadeException cfe) {
                    errorReturn(resp, cfe);
                    return;
                }
            }
            if (entity instanceof EventInfo) {
                // This might be a single event or a recurring event.
                final EventInfo ei = (EventInfo) entity;
                final BwEvent ev = ei.getEvent();
                if (ev.getRecurring()) {
                    resp.incRecurring();
                }
                if (!reindexEvent(hitResp, indexName, hit, ei, bulkProcessor)) {
                    warn("Unable to iondex event " + hit.sourceAsString());
                    resp.incTotalFailed();
                    if (resp.getTotalFailed() < 50) {
                        resp.addFailure(hitResp);
                    }
                }
            } else {
                final EsDocInfo doc = makeDoc(resp, entity);
                if (doc == null) {
                    if (resp.getStatus() != ok) {
                        resp.addFailure(hitResp);
                    }
                    continue;
                }
                final IndexRequest request = new IndexRequest(indexName, hit.type(), doc.getId());
                request.source(doc.getSource());
                bulkProcessor.add(request);
                if (entity instanceof BwEventProperty) {
                    if (!cacheEvprop(hitResp, (BwEventProperty) entity)) {
                        resp.addFailure(hitResp);
                    }
                }
            }
        }
        scrollResp = cl.prepareSearchScroll(scrollResp.getScrollId()).setScroll(tv).execute().actionGet();
        // Break condition: No hits are returned
        if (scrollResp.getHits().getHits().length == 0) {
            break;
        }
    }
    try {
        bulkProcessor.awaitClose(10, TimeUnit.MINUTES);
    } catch (final InterruptedException e) {
        errorReturn(resp, "Final bulk close was interrupted. Records may be missing", failed);
    }
    if (uidsSet > 0) {
        info("Uids set: " + uidsSet);
        info("uidOverridesSet: " + uidOverridesSet);
    }
    uidsMap = null;
    uidsOverideMap = null;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProperty(org.bedework.calfacade.BwEventProperty) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FilteredQueryBuilder(org.elasticsearch.index.query.FilteredQueryBuilder) IndexRequest(org.elasticsearch.action.index.IndexRequest) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) SearchResponse(org.elasticsearch.action.search.SearchResponse) ReindexResponse(org.bedework.calfacade.indexing.ReindexResponse) BwShareableDbentity(org.bedework.calfacade.base.BwShareableDbentity) BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) EsDocInfo(org.bedework.util.elasticsearch.EsDocInfo) TransportClient(org.elasticsearch.client.transport.TransportClient) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)5 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)3 BwEvent (org.bedework.calfacade.BwEvent)1 BwEventProperty (org.bedework.calfacade.BwEventProperty)1 BwShareableDbentity (org.bedework.calfacade.base.BwShareableDbentity)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 ReindexResponse (org.bedework.calfacade.indexing.ReindexResponse)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1 EsDocInfo (org.bedework.util.elasticsearch.EsDocInfo)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 Client (org.elasticsearch.client.Client)1 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)1 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)1 TransportClient (org.elasticsearch.client.transport.TransportClient)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1