Created
April 20, 2011 10:33
-
-
Save lukas-vlcek/930958 to your computer and use it in GitHub Desktop.
Indexing documents in a batch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void execute() { | |
int c = threadCounter.incrementAndGet(); | |
log.info("Starting a batch with {} items. ({} threads are running)", mails.size(), c); | |
for (JsonMail mail : mails) { | |
try { | |
IndexResponse indexResponse = ElasticSearchClient.getClient().prepareIndex() | |
.setIndex(indexName) | |
.setType("mail") | |
.setId(mail.getMessageId()) | |
.setSource(mail.getJsoncontent()) | |
.execute().actionGet(); | |
// log.info("Indexing OK: {} {} {}", | |
// new Object[]{indexResponse.index().toString(), indexResponse.type().toString(), indexResponse.id().toString()}); | |
} catch (Throwable e) { | |
log.error("Indexing failed: ",e); | |
} | |
} | |
c = threadCounter.decrementAndGet(); | |
log.info("Batch finished. ({} threads are running)", c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment