spriingboot集成ES
创建项目
使用阿里云创建boot项目 勾选上非关系形数据库中的ES即可
注意查看连接客户端的版本不要低于你使用的ES版本

如果要修改在该处插上代码段即可

测试使用
根据官方文档 要使用我们就需要初始化一个客户端对象

我们使用springboot的手段初始化对象
@Configuration
public class ElasticSearchConfig {
@Bean
public RestHighLevelClient restHighLevelClient(){
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("192.168.198.129", 9200, "http")));
return client;
}
}
测试使用
@Autowired
@Qualifier("restHighLevelClient")
private RestHighLevelClient client;
@Test
void contextLoads() throws IOException {
//创建索引请求
CreateIndexRequest request = new CreateIndexRequest("jie_index");
//执行
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
System.out.println(createIndexResponse);
}
运行结果:


整合成功!

浙公网安备 33010602011771号