亚洲国内精品自在线影视,国产成人色美女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]

相關閱讀

冕宁县| 兴文县| 江孜县| 昭通市| 云浮市| 潜江市| 清水河县| 垣曲县| 黄龙县| 阿巴嘎旗| 云梦县| 乐东| 桐城市| 嘉峪关市| 青冈县| 龙胜| 西乌珠穆沁旗| 香港| 龙山县| 九寨沟县| 彩票| 买车| 敦煌市| 陵川县| 溧水县| 多伦县| 成安县| 信宜市| 珠海市| 金坛市| 永平县| 济南市| 海伦市| 鄂伦春自治旗| 威宁| 桐庐县| 西乡县| 运城市| 贺州市| 蒙自县| 康乐县|