聊聊 Elastic-Search 部署和應(yīng)用
作者:程序員Lelonta
Elasticsearch 是一個(gè)分布式可擴(kuò)展的實(shí)時(shí)搜索和分析引擎,一個(gè)建立在全文搜索引擎 Apache Lucene(TM) 基礎(chǔ)上的搜索引擎。
es簡(jiǎn)介
Elasticsearch 是一個(gè)分布式可擴(kuò)展的實(shí)時(shí)搜索和分析引擎,一個(gè)建立在全文搜索引擎 Apache Lucene(TM) 基礎(chǔ)上的搜索引擎
Elastic官網(wǎng)
https://www.elastic.co/cn/
主要功能:
分布式搜索
數(shù)據(jù)分析
分組和聚合
es下載地址
https://www.elastic.co/cn/downloads/
linux安裝es
- 將下載的安裝包上傳導(dǎo)linux服務(wù)器,我的版本是elasticsearch-7.2.0-linux-x86_64.tar.gz
- 創(chuàng)建usr/local/soft/es目錄,將es解壓到這個(gè)目錄中
- 修改es的yum文件
node.name: node-1
// 這個(gè)很重要
http.host: 0.0.0.0
http.port: 9200
- 修改es的jvm.options
-Xms256M
-Xmx256M
- 創(chuàng)建新的用戶來啟動(dòng)es
- useradd esuser
- 賦予權(quán)限
chown -R esuser:esuser /usr/local/software/elasticsearch-7.2.0
- 切換到esuser用戶
su esuser
- 通過es用戶后臺(tái)啟動(dòng)es
sh elasticsearch -d
- 驗(yàn)證是否啟動(dòng)成功
curl -X GET "http://localhost:9200"
添加ik到es中
- 下載ik的版本必須和es版本對(duì)應(yīng)
- 將ik放到es的plugin目錄下進(jìn)行解壓
es重啟后會(huì)加載ik
es中新增索引post
curl -X PUT "localhost:9200/post"
將分詞器修改成ik
- 關(guān)閉索引
POST post/_close
- 配置ik
PUT post/_settings
{
"number_of_replicas": 0,
"index":{
"analysis.analyzer.default.type":"ik_max_word",
"analysis.search_analyzer.default.type":"ik_smart"
}
}
- 開啟post索引
POST post/_open
創(chuàng)建es的mapping,根據(jù)自己的需求創(chuàng)建
curl --location --request PUT '787k.fun:9200/post/_mapping' \
--header 'Content-Type: application/json' \
--data-raw '{
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "text"
},
"content": {
"type": "text"
},
"blogImg": {
"type": "keyword"
},
"html_content": {
"type": "keyword"
},
"authorId": {
"type": "integer"
},
"authorName": {
"type": "keyword"
},
"tag": {
"type": "integer"
},
"type": {
"type": "integer"
},
"status": {
"type": "integer"
},
"commentCount": {
"type": "integer"
},
"score": {
"type": "double"
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
}
}'
springboot集成es
- pom文件加入依賴
<!--es開始-->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.2.0</version>
</dependency>
<!--es結(jié)束-->
- yum文件添加文件
elasticsearch.host=localhost
elasticsearch.port=9200
責(zé)任編輯:武曉燕
來源:
今日頭條