- Java Transport Client (deprecated): other versions:
- Preface
- Maven Repository
- Dealing with JAR dependency conflicts
- Embedding jar with dependencies
- Deploying in JBoss EAP6 module
- Client
- Document APIs
- Search API
- Aggregations
- Query DSL
- Indexed Scripts API
- Java API Administration
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Bulk API
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Bulk API
editThe bulk API allows one to index and delete several documents in a single request. Here is a sample usage:
import static org.elasticsearch.common.xcontent.XContentFactory.*; BulkRequestBuilder bulkRequest = client.prepareBulk(); // either use client#prepare, or use Requests# to directly build index/delete requests bulkRequest.add(client.prepareIndex("twitter", "tweet", "1") .setSource(jsonBuilder() .startObject() .field("user", "kimchy") .field("postDate", new Date()) .field("message", "trying out Elasticsearch") .endObject() ) ); bulkRequest.add(client.prepareIndex("twitter", "tweet", "2") .setSource(jsonBuilder() .startObject() .field("user", "kimchy") .field("postDate", new Date()) .field("message", "another post") .endObject() ) ); BulkResponse bulkResponse = bulkRequest.get(); if (bulkResponse.hasFailures()) { // process failures by iterating through each bulk response item }
Was this helpful?
Thank you for your feedback.