Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2017 19:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import io.searchbox.core.Update;
import io.searchbox.core.Bulk;
import io.searchbox.core.Bulk.Builder;
import io.searchbox.action.BulkableAction;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.JestResult;
import io.searchbox.client.config.HttpClientConfig;
//initialise objects required to do bulk updates
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
client = factory.getObject();
current_bulkable_action = 0;
bulkProcessor = new Bulk.Builder();
// the below assumes "hit" comes from the ES document you'd like to update
String ES_ID = this.hit.get("_id").getAsString();
String ES_INDEX = this.hit.get("_index").getAsString();
String ES_TYPE = this.hit.get("_type").getAsString();
jsonUpdateObject = jsonBuilder().startObject().startObject("doc");
.field("foo", "bar")
.field("john", "doe");
update_builder = new Update.Builder(this.jsonUpdateObject.string()).index(ES_INDEX).id(ES_ID).type(ES_TYPE).build());
current_bulkable_action += 1;
if (current_bulkable_action > 1000) {
try {
System.out.println("Flushing BULK processor");
current_bulkable_action = 0;
} catch (IOException e) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment