一、在ecs-common工程下添加依赖包
<!--spring整合elasticsearch包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!--QueryDSL查询框架,通过API方式来构建查询-->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
二、在ec-impl-goods工程ApplicationGoods启动类加上如下方法
/**
* 初始化es客户端组件RestHighLevelClient,其封装了操作es的crud方法
* @return
* @throws IOException
*/
@Bean
public RestHighLevelClient getRestHighLevelClient() throws IOException {
RestHighLevelClient client = null;
try {
client = new RestHighLevelClient(
RestClient.builder(
new HttpHost(InetAddress.getByName("192.168.217.110"),9200,"http"),
new HttpHost(InetAddress.getByName("192.168.217.110"),9201,"http")));
log.info("ElasticSearch初始化完成。。");
} catch (Exception e) {
e.printStackTrace();
log.error("ElasticSearch初始化失败:" + e.getMessage(),e);
client.close();
}
return client;
}