亚洲国内精品自在线影视,国产成人色美女av网址,日本老太婆XXXB视频,浓逼毛美女掰逼

您的位置:首頁 > 要聞 >

世界百事通!SpringBoot整合ElasticSearch

2023-03-25 22:02:17 來源:騰訊云

ElasticSearch是個開源分布式搜索引擎,提供搜集、分析、存儲數(shù)據(jù)三大功能。它的特點有:分布式,零配置,自動發(fā)現(xiàn),索引自動分片,索引副本機制,restful風格接口,多數(shù)據(jù)源,自動搜索負載等。主要負責將日志索引并存儲起來,方便業(yè)務方檢索查詢。

1 安裝ES

下載地址:https://www.elastic.co/cn/downloads/elasticsearch

選擇Windows版本,我下載的是7.17.0。解壓后即可完成安裝。


(相關資料圖)

進入bin文件, 雙擊執(zhí)行 elasticsearch.bat,然后打開瀏覽器,進入頁面: http://localhost:9200,看到以下輸出,表示啟動成功。

2 Spring項目

項目GitHub地址:https://github.com/Snowstorm0/learn-es

項目Gitee地址:https://gitee.com/Snowstorm0/learn-es

2.1 配置ES客戶端

public class RestClientConfig extends AbstractElasticsearchConfiguration {    @Override    @Bean    public RestHighLevelClient elasticsearchClient() {        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()                .connectedTo("localhost:9200")                .build();        return RestClients.create(clientConfiguration).rest();    }}

2.2 創(chuàng)建User類

public class UserEntity {    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Integer id;    private String name;    private String job;    private Double deposit;    private Date processTime = new Date();}

配置完成后,ElasticSearch即可像常規(guī)的數(shù)據(jù)庫那樣進行增刪改查的操作。

2.3 配置數(shù)據(jù)庫

spring.datasource.username=rootspring.datasource.password=rootspring.datasource.url=jdbc:mysql://localhost:3306/sys?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

3 運行項目

3.1 添加

調用添加接口:http://localhost:8080/user/add

添加User類的請求體:

{  "id":"1",  "name":"代碼的路",  "job":"碼農",  "deposit":100.0}

可以看到添加成功:

3.2 讀取

運行讀取接口:http://localhost:8080/user/search/whole?key=碼農

可以獲得剛寫入的User類,是完整結構:

運行讀取接口:http://localhost:8080/user/search/es?key=碼農

可以獲得剛寫入的User類,只有User結構:

打開數(shù)據(jù)庫,無需手動創(chuàng)建表結構,即可看到User類也已經(jīng)寫入到數(shù)據(jù)庫中:

因此可以刻直接從數(shù)據(jù)庫讀取。

關鍵詞:

[責任編輯:xwzkw]

相關閱讀

大悟县| 金堂县| 大理市| 合阳县| 利川市| 涞源县| 越西县| 郯城县| 安康市| 鄄城县| 横山县| 阿拉善盟| 卫辉市| 桓仁| 抚顺市| 海城市| 乌兰浩特市| 胶州市| 张掖市| 都兰县| 宾川县| 忻城县| 临海市| 大宁县| 紫阳县| 伊川县| 塘沽区| 西贡区| 合山市| 武安市| 于都县| 黔江区| 体育| 平度市| 津南区| 调兵山市| 上犹县| 泰兴市| 临邑县| 肇源县| 遵化市|