# Elasticsearch-ESClientRHL-Spring
**Repository Path**: zxporz/elasticsearch-esclient-rhl-spring
## Basic Information
- **Project Name**: Elasticsearch-ESClientRHL-Spring
- **Description**: 包含ESClientRHL单纯spring版本(非springboot)以及一个集成demo
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 5
- **Forks**: 2
- **Created**: 2021-04-09
- **Last Updated**: 2024-04-09
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Elasticsearch-ESClientRHL-Spring
# 介绍
包含ESClientRHL单纯spring版本(非springboot)以及一个集成demo
# 项目说明
ESClientRHLSpring为ESClientRHL的工具jar
esclientrhlDemo4spring为集成了ESClientRHL的demo项目(虽然用springboot构建但并未使用springboot特性)
# 特别说明
1. 此项目更多的目的是演示(如何与普通spring项目集成),并不跟随主版本更新
2. 目前不支持es6+的版本,如有需要请自行改造
3. 此项目也暂时不会上传maven中央库,请自行install
4. 更多使用说明同
[Elasticsearch-ESClientRHL]: https://gitee.com/zxporz/ESClientRHL
# 使用教程
## pom引入
```
cn.zxporz
esclientrhlspring
7.0.2
```
## 配置
创建配置类,并配置扫描ESClientRHLSpring项目的包以及配置es地址等信息
```
@Component
@ComponentScan("org.zxp.esclientrhlspring")
public class InitConfig {
@Bean
public ElasticsearchProperties4Spring elasticsearchProperties4Spring(){
ElasticsearchProperties4Spring properties = new ElasticsearchProperties4Spring();
properties.setHost("127.0.0.1:9200");
return properties;
}
}
```
## 使用
```
@Autowired
ElasticsearchIndex elasticsearchIndex;
@Autowired
ElasticsearchTemplate elasticsearchTemplate;
@Test
void testCreateIndex() throws Exception {
elasticsearchIndex.createIndex(IndexDemoSpring.class);
}
@Test
void testSave() throws Exception {
IndexDemoSpring main1 = new IndexDemoSpring();
main1.setProposal_no("main1123123123");
main1.setAppli_code("123");
main1.setAppli_name("2");
main1.setRisk_code("0501");
main1.setSum_premium(100);
main1.setOperate_date(new Date());
elasticsearchTemplate.save(main1);
}
@Test
void testSearch() throws Exception {
elasticsearchTemplate.search(QueryBuilders.matchAllQuery(),IndexDemoSpring.class).forEach(System.out::println);
}
```