Created
April 2, 2015 18:56
-
-
Save nmunro-cvt/0be42236e9abf4359a44 to your computer and use it in GitHub Desktop.
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
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; | |
import java.util.Date; | |
import org.elasticsearch.action.ActionListener; | |
import org.elasticsearch.action.bulk.BulkRequestBuilder; | |
import org.elasticsearch.action.bulk.BulkResponse; | |
import org.elasticsearch.client.transport.TransportClient; | |
import com.cvent.common.ElasticsearchClientFactory; | |
public class BulkRequestWithListener { | |
public static final void main(String[] args) throws Exception { | |
TransportClient client = ElasticsearchClientFactory.getTransportClient(); | |
BulkRequestBuilder bulkRequest = client.prepareBulk(); | |
bulkRequest.add(client.prepareIndex("twitter", "tweet", "2") | |
.setSource(jsonBuilder() | |
.startObject() | |
.field("user", "kimchy") | |
.field("postDate", new Date()) | |
.field("message", "another post") | |
.endObject() | |
) | |
); | |
bulkRequest.execute() | |
.addListener(new ActionListener<BulkResponse>() { | |
public void onResponse(BulkResponse response) { | |
System.out.println(">>>>> onResponse"); | |
System.out.println(response.toString()); | |
} | |
public void onFailure(Throwable e) { | |
System.out.println(">>>>> onFailure"); | |
e.printStackTrace(); | |
} | |
}); | |
// keep main thread alive | |
Thread.sleep(10 * 1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment