SpringBoot + Elasticsearch5.x
来源:互联网 发布:淘宝客推广位有什么用 编辑:程序博客网 时间:2024/05/22 14:20
@Component@Configurationpublic class ElasticsearchConfiguration { private static final Logger logger = LoggerFactory.getLogger(ElasticsearchConfiguration.class); @Value("${es.cluster.nodes}") private String clusterNodes ; @Value("${es.cluster.name}") private String clusterName; private TransportClient client; @Bean public TransportClient init(){ logger.info("Building ElasticSearch client"); Settings settings = Settings.builder().put("cluster.name", clusterName).build(); client = new PreBuiltTransportClient(settings); try { if (!"".equals(clusterNodes)){ for (String nodes:clusterNodes.split(",")) { String InetSocket[] = nodes.split(":"); String address = InetSocket[0]; Integer port = Integer.valueOf(InetSocket[1]); client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(address), port)); } } } catch (Exception e) { logger.error("Error build ElasticSearch client: {}", e.getMessage()); } return client; } @PreDestroy public void destory() { if (client != null){ client.close(); } }}
项目源码:点击打开链接
阅读全文
0 0
- SpringBoot + Elasticsearch5.x
- Elasticsearch5.5+SpringBoot 2.0实践
- elasticsearch5.x服务器搭建
- Elasticsearch5.X配置说明
- Elasticsearch5.X索引
- Elasticsearch5.X聚合简介
- elasticsearch5.x下载与启动
- elasticsearch5.x之Slice scroll
- Elasticsearch5.X head插件安装
- ElasticSearch5.X 增删改查
- Elasticsearch5.X DSL常用用法
- ElasticSearch5.X尝试聚合(一)
- Elasticsearch5.x Head插件安装
- windows下安装elasticSearch5.X head插件
- linux安装elasticsearch5.0.x-安装篇
- centos7 elasticsearch5.2.2安装x-pack
- ELK系列一:CentOS7安装elasticsearch5.x
- ElasticSearch5.x版本安装遇到的问题
- 嵌入式驱动开发总结
- 264. Ugly Number II
- Ionic学习笔记——环境搭建
- Yii的AR模式及DAO
- STM8S复位总结
- SpringBoot + Elasticsearch5.x
- c语言排列组合还可以这样求
- XML基础
- 《编程题》组装三角形
- 迷宫算法
- 设计模式之单例设计模式
- 进程之间的同步方式有哪些
- 临江仙 夜饮东坡醒复醉
- windows下编译protobuf