首页 > 编程语言> > Caused by: java.net.SocketTimeoutException: 30,000 milliseconds timeout on elasticsearch 超时问题
Caused by: java.net.SocketTimeoutException: 30,000 milliseconds timeout on elasticsearch 超时问题
作者:互联网
/**
* 查询所有酒店信息
*/
List<TabHotel> records= tabHotelMapper.getHotelList();
System.out.println("酒店数据"+records);
//将数据保存带es中
//1 给es中建立索引 product 建立好映射关系
//2 保存数据到es中
BulkRequest bulkRequest = new BulkRequest();
for (TabHotel skuEsModel : records) {
//放到哪个索引?
IndexRequest indexRequest = new IndexRequest("travel_hotel");
indexRequest.id(skuEsModel.getId());
String jsonString = JSON.toJSONString(skuEsModel);
indexRequest.source(jsonString, XContentType.JSON);
bulkRequest.add(indexRequest);
}
System.out.println("酒店数据ser"+bulkRequest);
//执行
BulkResponse bulk = restHighLevelClient.bulk(bulkRequest, ElasticSearchConfig.COMMON_OPTIONS);
//TODO 如果批量错误
boolean b = bulk.hasFailures();
List<String> collect = Arrays.stream(bulk.getItems()).map(item -> {
return item.getId();
}).collect(Collectors.toList());
log.info("酒店信息上传完成:{},返回数据:{}", collect, bulk.toString());
System.out.println(b);
}
cluster.initial_master_nodes: ["127.0.0.1:9200"] |
在elasticsearch 的config/elasticsearch.yml 下 添加 cluster.initial_master_nodes: ["127.0.0.1:9200"] 后重新启动,问题解决。
标签:SocketTimeoutException,java,Caused,indexRequest,System,bulk,records,println,bulk 来源: https://www.cnblogs.com/striveliao/p/16495622.html