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

相關閱讀

元阳县| 乐昌市| 怀远县| 桂阳县| 抚顺县| 平安县| 宝清县| 河南省| 西藏| 洛宁县| 黔西县| 百色市| 肃北| 鹤岗市| 泰来县| 佛坪县| 伊春市| 绥滨县| 尉氏县| 固始县| 湘潭市| 长垣县| 夏津县| 安吉县| 兴安盟| 石景山区| 青河县| 原阳县| 镇赉县| 永顺县| 青龙| 台中市| 绥棱县| 兴文县| 敦煌市| 岱山县| 枝江市| 旺苍县| 克拉玛依市| 和顺县| 孙吴县|