Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created April 20, 2011 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukas-vlcek/930958 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/930958 to your computer and use it in GitHub Desktop.
Indexing documents in a batch
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