本文整理匯總了Java中org.elasticsearch.client.transport.TransportClient.prepareBulk方法的典型用法代碼示例。如果您正苦於以下問題:Java TransportClient.prepareBulk方法的具體用法?Java TransportClient.prepareBulk怎麽用?Java TransportClient.prepareBulk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.client.transport.TransportClient
的用法示例。
在下文中一共展示了TransportClient.prepareBulk方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: batchDelete
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
/**
* 批量刪除
*
* @param transportClient
*/
private static void batchDelete(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
DeleteRequestBuilder deleteRequestBuilder1 = transportClient.prepareDelete("product_index", "product", "1");
DeleteRequestBuilder deleteRequestBuilder2 = transportClient.prepareDelete("product_index", "product", "2");
DeleteRequestBuilder deleteRequestBuilder3 = transportClient.prepareDelete("product_index", "product", "3");
bulkRequestBuilder.add(deleteRequestBuilder1);
bulkRequestBuilder.add(deleteRequestBuilder2);
bulkRequestBuilder.add(deleteRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例2: batchUpdate
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
/**
* 批量更新
*
* @param transportClient
*/
private static void batchUpdate(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
UpdateRequestBuilder updateRequestBuilder1 = transportClient.prepareUpdate("product_index", "product", "1")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新後的商品名稱1")
.endObject());
UpdateRequestBuilder updateRequestBuilder2 = transportClient.prepareUpdate("product_index", "product", "2")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新後的商品名稱2")
.endObject());
UpdateRequestBuilder updateRequestBuilder3 = transportClient.prepareUpdate("product_index", "product", "3")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新後的商品名稱3")
.endObject());
bulkRequestBuilder.add(updateRequestBuilder1);
bulkRequestBuilder.add(updateRequestBuilder2);
bulkRequestBuilder.add(updateRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例3: bulkSaveOrUpdate
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
/**
* 批量save
* @param indexName
* @param indexType
* @param list
* @return
*/
private BulkResponse bulkSaveOrUpdate(String indexName, String indexType, List<DocPo> list){
TransportClient client = esClientFactory.getClient();
BulkResponse bulkResponse=null;
BulkRequestBuilder bulkRequest = client.prepareBulk();
for(int i=0;i<list.size();i++){
bulkRequest.add(new IndexRequest(esClientFactory.getIndexs(indexName), indexType,list.get(i).getId()).source(JSON.toJSONString(list.get(i).getObj())));
}
bulkResponse = bulkRequest.get();
// 處理錯誤信息
handBulkResponseException(bulkResponse);
return bulkResponse;
}
示例4: bulkDelete
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
/**
* 批量del
* @param indexName
* @param indexType
* @param
* @return
*/
private BulkResponse bulkDelete(String indexName, String indexType, List<String> ids){
TransportClient client = esClientFactory.getClient();
BulkResponse bulkResponse=null;
BulkRequestBuilder bulkRequest = client.prepareBulk();
for(int i=0;i<ids.size();i++){
bulkRequest.add(new DeleteRequest(esClientFactory.getIndexs(indexName), indexType,ids.get(i) ));
}
bulkResponse = bulkRequest.get();
// 處理錯誤信息
handBulkResponseException(bulkResponse);
return bulkResponse;
}
示例5: batchCreate
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
/**
* 批量創建
* 資料:http://blog.csdn.net/loveisnull/article/details/45914115
* 緯度在前,經度在後
*
* @param transportClient
*/
private static void batchCreate(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
IndexRequestBuilder indexRequestBuilder1 = transportClient.prepareIndex("shop_index", "shop", "1")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("shop_name", "麻辣香鍋1")
.latlon("location", 40.12, -71.34)
.field("created_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("last_modified_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("version", 1)
.endObject());
IndexRequestBuilder indexRequestBuilder2 = transportClient.prepareIndex("shop_index", "shop", "2")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("shop_name", "麻辣香鍋2")
.latlon("location", 40.12, -72.34)
.field("created_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("last_modified_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("version", 1)
.endObject());
IndexRequestBuilder indexRequestBuilder3 = transportClient.prepareIndex("shop_index", "shop", "3")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("shop_name", "麻辣香鍋3")
.latlon("location", 40.12, -73.34)
.field("created_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("last_modified_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("version", 1)
.endObject());
bulkRequestBuilder.add(indexRequestBuilder1);
bulkRequestBuilder.add(indexRequestBuilder2);
bulkRequestBuilder.add(indexRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例6: batchCreate
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
/**
* 批量創建
*
* @param transportClient
*/
private static void batchCreate(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
IndexRequestBuilder indexRequestBuilder1 = transportClient.prepareIndex("product_index", "product", "1")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "飛利浦電動牙刷 HX6700-1")
.field("product_desc", "前 1000 名贈刷頭,6 月 1 日 0 點火爆開搶,618 開門紅巔峰 48 小時")
.field("price", 399.00)
.field("created_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("last_modified_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("version", 1)
.endObject());
IndexRequestBuilder indexRequestBuilder2 = transportClient.prepareIndex("product_index", "product", "2")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "飛利浦電動牙刷 HX6700-2")
.field("product_desc", "前 1000 名贈刷頭,6 月 1 日 0 點火爆開搶,618 開門紅巔峰 48 小時")
.field("price", 399.00)
.field("created_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("last_modified_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("version", 1)
.endObject());
IndexRequestBuilder indexRequestBuilder3 = transportClient.prepareIndex("product_index", "product", "3")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "飛利浦電動牙刷 HX6700-3")
.field("product_desc", "前 1000 名贈刷頭,6 月 1 日 0 點火爆開搶,618 開門紅巔峰 48 小時")
.field("price", 399.00)
.field("created_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("last_modified_date_time", new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ").format(new Date()))
.field("version", 1)
.endObject());
bulkRequestBuilder.add(indexRequestBuilder1);
bulkRequestBuilder.add(indexRequestBuilder2);
bulkRequestBuilder.add(indexRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例7: importAllItems
import org.elasticsearch.client.transport.TransportClient; //導入方法依賴的package包/類
@Override
public int importAllItems() {
try{
Settings settings = Settings.builder()
.put("cluster.name", "xmall").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ES_CONNECT_IP), 9300));
//批量添加
BulkRequestBuilder bulkRequest = client.prepareBulk();
//查詢商品列表
List<SearchItem> itemList = itemMapper.getItemList();
//遍曆商品列表
for (SearchItem searchItem : itemList) {
String image=searchItem.getProductImageBig();
if (image != null && !"".equals(image)) {
String[] strings = image.split(",");
image=strings[0];
}else{
image="";
}
searchItem.setProductImageBig(image);
bulkRequest.add(client.prepareIndex("item", "itemList", String.valueOf(searchItem.getProductId()))
.setSource(jsonBuilder()
.startObject()
.field("productId", searchItem.getProductId())
.field("salePrice", searchItem.getSalePrice())
.field("productName", searchItem.getProductName())
.field("sub_title", searchItem.getSub_title())
.field("productImageBig", searchItem.getProductImageBig())
.field("category_name", searchItem.getCategory_name())
.endObject()
)
);
}
BulkResponse bulkResponse = bulkRequest.get();
log.info("更新索引成功");
client.close();
}catch (Exception e){
e.printStackTrace();
throw new XmallException("導入ES索引庫出錯");
}
return 1;
}