Skip to content

Instantly share code, notes, and snippets.

@kimchy
Created April 14, 2011 18:34
Show Gist options
  • Select an option

  • Save kimchy/920160 to your computer and use it in GitHub Desktop.

Select an option

Save kimchy/920160 to your computer and use it in GitHub Desktop.
package com.edmunds.training.real_time_logger;
import java.io.IOException;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.action.bulk.BulkRequestBuilder;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
public class BulkProcessorTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
BulkRequestBuilder request = client.prepareBulk();
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
builder.field("firstname", "John");
builder.field("lastname", "Lee");
builder.endObject();
request.add(Requests.indexRequest("testindex").type("my_type")
.source(builder));
builder = XContentFactory.jsonBuilder().startObject();
builder.field("firstname", "Rick");
builder.field("lastname", "Hammer");
builder.endObject();
request.add(Requests.indexRequest("testindex").type("my_type")
.source(builder));
BulkResponse response = request.execute().actionGet();
if (response.hasFailures()) {
System.out.println("Bulk request failed");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment