Es7.x使用RestHighLevelClient进行增删改和批量操作

更新时间:2023-06-26 16:11:22 阅读: 评论:0

TransportClient这个是已经废弃不⽤的,所以会在ES8.0之后完全移除,也就是说8.0之后就⽆法使⽤了。@Slf4j
public class EsTest {
//es操作客户端
private static RestHighLevelClient restHighLevelClient;
//批量操作的对象
private static BulkProcessor bulkProcessor;
static {
List<HttpHost> httpHosts = new ArrayList<>();
//填充数据
httpHosts.add(new HttpHost("172.26.17.11", 9200));
httpHosts.add(new HttpHost("172.26.17.11", 9201));
httpHosts.add(new HttpHost("172.26.17.11", 9202));
//填充host节点
RestClientBuilder builder = RestClient.Array(new HttpHost[0]));
builder.tRequestConfigCallback(requestConfigBuilder -> {心理剧剧本
requestConfigBuilder.tConnectTimeout(1000);
requestConfigBuilder.tSocketTimeout(1000);
requestConfigBuilder.tConnectionRequestTimeout(1000);
return requestConfigBuilder;
});
//填充⽤户名密码
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();蒸螃蟹冷水蒸还是开水
credentialsProvider.tCredentials(AuthScope.ANY, new UrnamePasswordCredentials("urName", "password"));
builder.tHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.tMaxConnTotal(30);
httpClientBuilder.tMaxConnPerRoute(30);
httpClientBuilder.tDefaultCredentialsProvider(credentialsProvider);食品检测
校园十佳歌手
return httpClientBuilder;
});自驾旅游
相处融洽restHighLevelClient = new RestHighLevelClient(builder);
}
static {
bulkProcessor=createBulkProcessor();
}
private static BulkProcessor createBulkProcessor() {
BulkProcessor.Listener listener = new BulkProcessor.Listener() {
女娲日记@Override
public void beforeBulk(long executionId, BulkRequest request) {
log.info("1. 【beforeBulk】批次[{}] 携带 {} 请求数量", executionId, request.numberOfActions());
}
@Override
public void afterBulk(long executionId, BulkRequest request,
BulkRespon respon) {
if (!respon.hasFailures()) {
log.info("2. 【afterBulk-成功】批量 [{}] 完成在 {} ms", executionId, Took().getMillis());
} el {
BulkItemRespon[] items = Items();
for (BulkItemRespon item : items) {
if (item.isFailed()) {
log.info("2. 【afterBulk-失败】批量 [{}] 出现异常的原因 : {}", executionId, FailureMessage());
break;
}
}
}
}
演员和歌手
@Override
public void afterBulk(long executionId, BulkRequest request,

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

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1055955.html

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

标签:填充   操作   歌手   批量   螃蟹   心理剧   食品
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图