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,