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

相關閱讀

枣阳市| 安岳县| 乌兰县| 聊城市| 旌德县| 河东区| 长顺县| 五莲县| 枣强县| 灌云县| 城口县| 阿荣旗| 锡林浩特市| 奎屯市| 句容市| 惠东县| 沅江市| 德庆县| 安宁市| 庆阳市| 三都| 德令哈市| 三门峡市| 自治县| 宾阳县| 梨树县| 加查县| 武功县| 泰安市| 佛坪县| 涡阳县| 贡嘎县| 遵化市| 通化县| 宁安市| 蕉岭县| 梅州市| 舞钢市| 长泰县| 新兴县| 福州市|