本文整理汇总了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;
}