ES的BulkProcessor实现批量写入

更新时间:2023-06-26 15:26:36 阅读: 评论:0

ES的BulkProcessor实现批量写⼊
这是读取的⽂件
0,联想(Lenovo)拯救者Y7000P英特尔酷睿i7 15.6英⼨游戏笔记本电脑(8核i7-10875H 16G 512G RTX2060 144Hz)灰,/100013950500.html, 7299.0,联想京东⾃营旗舰店,200000,电脑,1000
0,联想ThinkPad E15 2021款酷睿版英特尔酷睿i5/i7 轻薄笔记本电脑⼈脸识别 i5-1135G7 16G 512G 1SCD,/10026505315633.html,5399. 0,ThinkPad京东官⽅⾃营旗舰店,5000,电脑,1000
0,惠普(HP)战66四代锐龙版14英⼨轻薄笔记本电脑(Zen3架构8核 R7-5800U 16G 512G 400尼特⾼⾊域⼀年上门),/100018080014.html,5 099.0,惠普京东⾃营官⽅旗舰店,200000,电脑,1000
0,华硕⽆畏Pro14 标压锐龙版2.8K OLED屏轻薄笔记本电脑(R7-5800H 16G 512G 133%sRGB⾼⾊域600尼特 90Hz)银,/100021150248.ht ml,4999.0,华硕京东⾃营官⽅旗舰店,5000,电脑,1000
0,联想YOGA 13s 2021款锐龙版13.3英⼨全⾯屏超轻薄笔记本电脑(6核 R5-5600U 16G 512G 2.5K⾼⾊域屏)深空灰,/100022002312.html, 4799.0,联想京东⾃营旗舰店,100000,电脑,1000
0,惠普(HP)星15 青春版15.6英⼨轻薄窄边框笔记本电脑(R7-4700U 16G 512GSSD UMA FHD IPS)银,/100014662878.html,4098.0,惠普京东⾃营官⽅旗舰店,20000,电脑,1000
0,宏碁(Acer)⾮凡S3超轻薄本全新升级14英⼨办公笔记本电脑⾼⾊域 Evo认证(11代酷睿i5 16G 512G 雷电4)银,/100018725930.html,43 99.0,宏碁京东⾃营旗舰店,2000,电脑,1000
0,联想笔记本电脑ThinkPad X1 Carbon 2021款英特尔Evo平台14英⼨11代酷睿i5 16G 512G ⾼⾊域 /4G全时互联,/100020822576.html,9 999.0,ThinkPad京东⾃营旗舰店,5000,电脑,1000
package Exe;
import ObjectMapper;
import SneakyThrows;
import HttpHost;
import Logger;
import ActionListener;
import BackoffPolicy;
import BulkProcessor;
import BulkRequest;
import BulkRespon;
import IndexRequest;
import RequestOptions;
import RestClient;
import RestHighLevelClient;
烧鸡怎么做import TransportClient;
import ByteSizeUnit;
import ByteSizeValue;
import TimeValue;
import XContentType;
import*;
import ArrayList;
import BiConsumer;
import ErrorManager;
public class Create_Mapping {
public static void main(String[] args){
Logger logger;
try{
File file=new File("D:\\JAVA_Workspace\\Java\\es\\src\\main\\java\\com\\example\\Exe\\zd");
// Create the low-level client
BulkProcessor bulkProcessor =bulkProcessor();
BufferedReader reader =new BufferedReader(new FileReader(file));
String temp=null;
int j=1;
while((adLine())!=null){
String[] line = temp.split(",");
Item_Detail item_detail=new Item_Detail();
item_detail.tName(line[1]);
item_detail.tUrl(line[2]);
item_detail.tPrice(Double.parDouble(line[3]));
item_detail.tFactory(line[4]);
item_detail.tComment(Long.parLong(line[5]));
item_detail.tKeyword(line[6]);
item_detail.tId(j);
item_detail.tNum(1000);
j=j+1;
System.out.println(String());
定的组词
/
/ 新增⽂档 - 请求对象
IndexRequest request =new IndexRequest();
// 设置索引及唯⼀性标识
十大豪车排行榜
request.index("item").id(String.valueOf(j));
ObjectMapper objectMapper =new ObjectMapper();
String productJson = objectMapper.writeValueAsString(item_detail);
// 添加⽂档数据,数据格式为 JSON 格式
request.source(productJson, XContentType.JSON);
bulkProcessor.add(new IndexRequest("item").id(String.valueOf(j)).source(productJson, XContentType.JSON));
//request.index("item").id(j);
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
/*
* 创建bulkProcessor
* */
public static BulkProcessor bulkProcessor(){
Logger logger =null;
RestHighLevelClient client =new RestHighLevelClient(
RestClient.builder(new HttpHost("hadoop101",9200,"http")));
BiConsumer<BulkRequest, ActionListener<BulkRespon>> bulkConsumer =
(request, bulkListener)-> client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener);
成人高考作文
return BulkProcessor.builder(bulkConsumer,new BulkProcessor.Listener(){
消防灭火演练@Override
public void beforeBulk(long executionId, BulkRequest request){
System.out.println("插⼊数据");
//在这⼉你可以⾃定义执⾏同步之前执⾏什么
}
@SneakyThrows
@Override
public void afterBulk(long executionId, BulkRequest request, BulkRespon respon){
System.out.println("写⼊完成");
//在这⼉你可以⾃定义执⾏完同步之后执⾏什么
}
@Override
@Override
public void afterBulk(long executionId, BulkRequest request, Throwable failure){
//写⼊失败后
<("ES写⼊失败", failure);
}
}).tBulkActions(100).tFlushInterval(TimeValue.timeValueSeconds(10)).build();//  达到刷新的条数// 固定刷新的时间频率
}
}
实体类
package Exe;
public class Item_Detail {
long id;
long comment;
String keyword;
String factory;
double price;
String url;
String name;
long num;
public long getNum(){
return num;
}
@Override
public String toString(){
return"Item_Detail{"+
"id="+ id +
", comment="+ comment +
", keyword='"+ keyword +'\''+
", factory='"+ factory +'\''+
", price="+ price +
", url='"+ url +'\''+
", name='"+ name +'\''+
", num="+ num +
'}';
}
public void tNum(long num){
this.num = num;
}
public long getId(){
return id;
}
public void tId(long id){
this.id = id;
}
public long getComment(){
return comment;
}
public void tComment(long comment){
}
public String getKeyword(){
return keyword;
}
public void tKeyword(String keyword){
this.keyword = keyword;
}
public String getFactory(){
return factory;
}
public void tFactory(String factory){
this.factory = factory;
}
public double getPrice(){动态路由配置
return price;
汉语言文学就业方向}
public void tPrice(double price){
this.price = price;
}
public String getUrl(){
return url;
}
最初的梦想歌词
public void tUrl(String url){
this.url = url;
}
public String getName(){
return name;
}
public void tName(String name){
this.name = name;
}
}

本文发布于:2023-06-26 15:26:36,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1044647.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图