美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

聊聊Elastic-Search部署和应用

es简介

Elastic官网

https://www.elastic.co/cn/

主要功能:

分布式搜索

数据分析

分组和聚合

es下载地址

https://www.elastic.co/cn/downloads/

linux安装es

  • 将下载的安装包上传导linux服务器,我的版本是elasticsearch-7.2.0-linux-x86_64.tar.gz
  • 创建usr/local/soft/es目录,将es解压到这个目录中
  • 修改es的yum文件
node.name: node-1
// 这个很重要
http.host: 0.0.0.0
http.port: 9200
  • 修改es的jvm.options
-Xms256M
-Xmx256M
  • 创建新的用户来启动es
  • useradd esuser
  • 赋予权限
chown -R esuser:esuser /usr/local/software/elasticsearch-7.2.0
  • 切换到esuser用户
su esuser
  • 通过es用户后台启动es
sh elasticsearch -d
  • 验证是否启动成功
curl -X GET "http://localhost:9200"

添加ik到es中

  • 下载ik的版本必须和es版本对应
  • 将ik放到es的plugin目录下进行解压

es重启后会加载ik

es中新增索引post

curl -X PUT "localhost:9200/post" 

将分词器修改成ik

  • 关闭索引
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

创建es的mapping,根据自己的需求创建

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文件加入依赖


org.elasticsearch.client
elasticsearch-rest-high-level-client
7.2.0


org.elasticsearch
elasticsearch
7.2.0

  • yum文件添加文件
elasticsearch.host=localhost
elasticsearch.port=9200

文章标题:聊聊Elastic-Search部署和应用
标题链接:http://www.zsjierui.cn/article/djehsei.html

其他资讯