日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語言 正文

elasticsearch + spring boot 配置

作者:山聞?dòng)? 更新時(shí)間: 2022-04-10 編程語言

目錄

首先引入elasticsearch依賴

操作?elasticsearch有兩種方式

一、通過elasticsearch?client操作elasticsearch

二、通過spring框架操作elasticsearch


首先引入elasticsearch依賴


    org.elasticsearch
    elasticsearch
    7.6.2

操作?elasticsearch有兩種方式

一、通過elasticsearch?client操作elasticsearch



    org.elasticsearch.client
    elasticsearch-rest-high-level-client
    7.6.2



    org.elasticsearch.plugin
    transport-netty4-client
    7.6.2

這種方式使用起來比較復(fù)雜,需要對(duì)API比較了解。適合需要定制化的需求。如果是簡(jiǎn)單的增刪除改查,還是用第二種方式用spring框架二次封裝,以O(shè)RM的方式對(duì)數(shù)據(jù)進(jìn)行操作可能更習(xí)慣使用。

//定義client鏈接
RestHighLevelClient client = new RestHighLevelClient(
		RestClient.builder(
				new HttpHost("localhost", 9200, "http"),
				new HttpHost("localhost", 9201, "http")));

// 然后用client進(jìn)行增刪改查

二、通過spring框架操作elasticsearch

引入依賴



	org.springframework.data
	spring-data-elasticsearch
	4.0.9.RELEASE



	org.springframework.boot
	spring-boot-starter-data-elasticsearch
	

?application.yml配置

#elasticsearch服務(wù)器連接配置
spring:
  data:
    elasticsearch:
      cluster-name: elasticsearch
      cluster-nodes: localhost:9300

?配置好之后通過繼承org.springframework.data.elasticsearch.repository.ElasticsearchRepository或使用ElasticsearchRestTemplate操作elasticsearch。

@Component
public interface IndexRepository extends ElasticsearchRepository {

}

或

@Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;

原文鏈接:https://blog.csdn.net/xjj1314/article/details/123788540

欄目分類
最近更新