private final String indexName;
private boolean large = false;
private long flushByteSize = FLUSH_BYTE_SIZE;
- private boolean disableRefresh = false;
private BulkRequestBuilder bulkRequest = null;
private Map<String, Object> largeInitialSettings = null;
private final AtomicLong counter = new AtomicLong(0L);
return this;
}
- /**
- * By default refresh of index is executed in method {@link #stop()}. Set to true
- * to disable refresh.
- */
- public BulkIndexer setDisableRefresh(boolean b) {
- this.disableRefresh = b;
- return this;
- }
-
@Override
public void start() {
Preconditions.checkState(bulkRequest == null, ALREADY_STARTED_MESSAGE);
throw new IllegalStateException("Elasticsearch bulk requests still being executed after 10 minutes", e);
}
progress.stop();
-
- if (!disableRefresh) {
- client.prepareRefresh(indexName).get();
- }
+ client.prepareRefresh(indexName).get();
if (large) {
// optimize lucene segments and revert index settings
// Optimization must be done before re-applying replicas:
public void deleteProject(String uuid) {
BulkIndexer bulk = new BulkIndexer(esClient, INDEX);
- bulk.setDisableRefresh(false);
bulk.start();
SearchRequestBuilder search = esClient.prepareSearch(INDEX)
.setTypes(TYPE_ISSUE, TYPE_AUTHORIZATION)
assertThat(count()).isEqualTo(removeFrom);
}
- @Test
- public void disable_refresh() {
- BulkIndexer indexer = new BulkIndexer(esTester.client(), FakeIndexDefinition.INDEX)
- .setDisableRefresh(true);
- indexer.start();
- indexer.add(newIndexRequest(42));
- indexer.add(newIndexRequest(78));
- indexer.stop();
-
- assertThat(count()).isEqualTo(0);
-
- esTester.client().prepareRefresh(FakeIndexDefinition.INDEX).get();
- assertThat(count()).isEqualTo(2);
- }
-
private long count() {
return esTester.countDocuments("fakes", "fake");
}