void testBulkProcessor(int processors) { logger.info("Test bulk processor with concurrent request: {}", processors); Stopwatch watcher = Stopwatch.createStarted(); try { indexedDocumentCount.set(0); bulkProcessor = BulkProcessor.builder(client, listener) .setBulkActions(DEFAULT_BULK_ACTIONS) .setConcurrentRequests(processors) // .setFlushInterval(DEFAULT_FLUSH_INTERVAL) .setBulkSize(DEFAULT_BULK_SIZE) .build(); if (client.admin().indices().prepareExists(INDEX_NAME).get().isExists()) { client.admin().indices().prepareDelete(INDEX_NAME).get(); } client.admin().indices().prepareCreate(INDEX_NAME).get(); logger.info( "Done Cluster Health, status: {}", client .admin() .cluster() .health(clusterHealthRequest().waitForGreenStatus()) .get() .getStatus()); for (int i = 0; i < MAX; i++) { Map<String, Object> data = new HashMap<String, Object>(); data.put("name", "test-" + i); data.put("date", new Date()); bulkProcessor.add( indexRequest(INDEX_NAME) .type(TYPE_NAME) .source(XContentFactory.jsonBuilder().map(data))); } bulkProcessor.close(); logger.info( "Done Cluster Health, status: {}", client .admin() .cluster() .health(clusterHealthRequest().waitForGreenStatus()) .get() .getStatus()); logger.info("Number of documents indexed from afterBulk: {}", indexedDocumentCount.get()); client.admin().indices().prepareRefresh(INDEX_NAME).get(); long count = client.prepareCount(INDEX_NAME).get().getCount(); logger.info("Number of documents: {} in index {}", count, INDEX_NAME); if (count != MAX) { throw new RuntimeException( String.format( "Number of documents indexed %s does not match the target %s", count, MAX)); } } catch (Throwable t) { logger.error("testBulkProcessor failed", t); } finally { watcher.stop(); logger.info("Elpased time: {}", watcher.toString()); if (client.admin().indices().prepareExists(INDEX_NAME).get().isExists()) { client.admin().indices().prepareDelete(INDEX_NAME).get(); try { client .admin() .cluster() .health(clusterHealthRequest().waitForGreenStatus()) .get() .getStatus(); } catch (Throwable t) { throw new RuntimeException(t); } } } }