第一步建立一个SpringBoot项目spring
点击Nextapache
修改成本身想要的名字以后点击下一步api
选择本身须要的依赖关系,点击Next网络
配置好路径后点击 Finishelasticsearch
等待项目构建完成后,记得看一下,ES 的版本ui
若是是低版本的springBoot 可能ES的版本比较低spa
建议修改成和本身使用的ES的版本一致3d
修改后点击Maven的刷新rest
刷新后发现,版本已经修改完毕code
编写配置类
package com.dance.danceesapi.config; import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * ElasticSearch配置类 * @author ZYGisComputer */ @Configuration public class ElasticSearchClientConfig { @Bean public RestHighLevelClient restHighLevelClient(){ return new RestHighLevelClient( RestClient.builder( new HttpHost("127.0.0.1",9200,"http") ) ); } }
在用的时候注入就能够了
package com.flower.floweres; import org.elasticsearch.client.RestHighLevelClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class FlowerEsApplication { @Autowired @Qualifier("restHighLevelClient") public RestHighLevelClient restHighLevelClient; public static void main(String[] args) { SpringApplication.run(FlowerEsApplication.class, args); } }
到此集成完毕
做者:彼岸舞
时间:2020\09\11
内容关于:ElasticSearch
本文来源于网络,只作技术分享,一律不负任何责任