PUT /car_shop/cars/3
{
"brand": "宝马",
"name": "宝马320",
"price": 320000,
"produce_date": "2018-01-01",
"sale_price": 300000,
"sale_date": "2018-01-21"
}
PUT /car_shop/cars/4
{
"brand": "宝马",
"name": "宝马320",
"price": 320000,
"produce_date": "2018-01-01",
"sale_price": 300000,
"sale_date": "2018-01-21"
}
Settings settings = Settings.builder()
.put("cluster.name", "my-application")
.put("client.transport.sniff", true)
.build();
TransportClient client = new PreBuiltTransportClient(settings).
addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.80.188"), 9300));
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
IndexRequestBuilder indexRequestBuilder = client.prepareIndex("car_shop", "cars", "5")
.setSource(XContentFactory.jsonBuilder().startObject()
.field("brand", "奔驰")
.field("name", "奔驰C200")
.field("price", 350000)
.field("produce_date", "2018-01-20")
.field("sale_price", 320000)
.field("sale_date", "2018-01-25")
.endObject()
);
bulkRequestBuilder.add(indexRequestBuilder);
UpdateRequestBuilder updateRequestBuilder = client.prepareUpdate("car_shop", "cars", "3")
.setDoc(XContentFactory.jsonBuilder().startObject().field("sale_price", 290000).endObject());
bulkRequestBuilder.add(updateRequestBuilder);
DeleteRequestBuilder deleteRequestBuilder = client.prepareDelete("car_shop", "cars", "4");
bulkRequestBuilder.add(deleteRequestBuilder);
BulkResponse bulkItemResponse = bulkRequestBuilder.get();
for (BulkItemResponse itemResponse : bulkItemResponse) {
System.out.println(itemResponse.getVersion());
}
client.close();