Created
April 14, 2011 18:34
-
-
Save kimchy/920160 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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