@Override public void stop() { if (bulkRequest.numberOfActions() > 0) { executeBulk(); } try { if (semaphore.tryAcquire(concurrentRequests, 10, TimeUnit.MINUTES)) { semaphore.release(concurrentRequests); } } catch (InterruptedException e) { throw new IllegalStateException( "Elasticsearch bulk requests still being executed after 10 minutes", e); } progress.stop(); if (!disableRefresh) { client.prepareRefresh(indexName).get(); } if (large) { // optimize lucene segments and revert index settings // Optimization must be done before re-applying replicas: // http://www.elasticsearch.org/blog/performance-considerations-elasticsearch-indexing/ client.prepareForceMerge(indexName).get(); updateSettings(largeInitialSettings); } bulkRequest = null; }
public void add(ActionRequest request) { bulkRequest.request().add(request); if (bulkRequest.request().estimatedSizeInBytes() >= flushByteSize) { executeBulk(); } }