1 Star 5 Fork 2

X-Pacific / Elasticsearch-ESClientRHL-Spring

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
X-Pacific 提交于 2021-04-09 14:19 . 1

Elasticsearch-ESClientRHL-Spring

介绍

包含ESClientRHL单纯spring版本(非springboot)以及一个集成demo

项目说明

ESClientRHLSpring为ESClientRHL的工具jar

esclientrhlDemo4spring为集成了ESClientRHL的demo项目(虽然用springboot构建但并未使用springboot特性)

特别说明

  1. 此项目更多的目的是演示(如何与普通spring项目集成),并不跟随主版本更新

  2. 目前不支持es6+的版本,如有需要请自行改造

  3. 此项目也暂时不会上传maven中央库,请自行install

  4. 更多使用说明同

使用教程

pom引入

<dependency>
    <groupId>cn.zxporz</groupId>
    <artifactId>esclientrhlspring</artifactId>
    <version>7.0.2</version>
</dependency>

配置

创建配置类,并配置扫描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<IndexDemoSpring> elasticsearchIndex;
	@Autowired
	ElasticsearchTemplate<IndexDemoSpring,String> 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);
	}
Java
1
https://gitee.com/zxporz/elasticsearch-esclient-rhl-spring.git
git@gitee.com:zxporz/elasticsearch-esclient-rhl-spring.git
zxporz
elasticsearch-esclient-rhl-spring
Elasticsearch-ESClientRHL-Spring
master

搜索帮助