*基于RuoYi-cloud3.5.0 + elasticsearch7的搜索引擎演示项目,使用2个经典案例(百度地图找房+文章内容搜索),演示es常用的功能及代码原生写法和简化写法(easy-es)~
记得右上角点个 star 持续关注更新哟~~
后台页面
需要对以下模块进行启动 启动顺序随意
yum install -y yum-utils
# 阿里云地址(国内地址,相对更快)
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
docker version # 查看Docker版本信息
systemctl status docker # 查看 docker 服务状态
systemctl start docker # 启动 docker 服务:
systemctl stop docker # 停止 docker 服务:
systemctl status docker # 查看 docker 服务状态
systemctl restart docker # 重启 docker 服务
vim /etc/docker/daemon.json
# 添加如下内容,可以自己替换。默认地址是我的创建的
{
"registry-mirrors": ["https://mr63yffu.mirror.aliyuncs.com"]
}
systemctl daemon-reload
systemctl restart docker # 重启 docker 服务
curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 将可执行权限应用于该二进制文件
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
mkdir -p /data/docker_data/es-kabana
mkdir -p /data/docker_data/es-kabana/es/config
touch /data/docker_data/es-kabana/docker-compose.yml
touch /data/docker_data/es-kabana/es/config/elasticsearch.yml
vim /data/docker_data/es-kabana/docker-compose.yml
vim /data/docker_data/es-kabana/es/config/elasticsearch.yml
cd /data/docker_data/es-kabana
docker-compose up -d 开启es
docker-compose down 关闭es
version: '3'
# 网桥es -> 方便相互通讯
networks:
es:
services:
elasticsearch:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/elasticsearch:7.14.1 # 原镜像`elasticsearch:7.14.1`
container_name: elasticsearch # 容器名为'elasticsearch'
restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
- "./es/data:/usr/share/elasticsearch/data"
- "./es/logs:/usr/share/elasticsearch/logs"
- "./es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
- "./es/plugins/:/usr/share/elasticsearch/plugins"
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
discovery.type: single-node
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
ELASTIC_PASSWORD: "123456" # elastic账号密码
ports:
- "9202:9200"
- "9302:9300"
networks:
- es
kibana:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/kibana:7.14.1 # 原镜像`kibana:7.14.1`
container_name: kibana
restart: unless-stopped
volumes:
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
- ./kibana/logs:/usr/share/kibana/logs
environment:
TZ: Asia/Shanghai # 更改容器时区为 CST(默认为UTC)
LANG: en_US.UTF-8
ports:
- "5601:5601"
depends_on:
- elasticsearch
links:
- elasticsearch
networks:
- es
elasticsearch-head:
image: wallbase/elasticsearch-head:6-alpine
container_name: elasticsearch-head
restart: unless-stopped
environment:
TZ: 'Asia/Shanghai'
ports:
- '9100:9100'
networks:
- es
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.port: 9200
# 开启es跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,Content-Type
# 开启安全控制
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
先去github下载分词包elasticsearch-analysis-ik-7.14.1.zip
然后解压到该目录下/data/docker_data/es-kabana/es/plugins/analysis-ik-7.14.1
请求方式:PUT (请使用postman进行访问)
请求地址:http://127.0.0.1:9202/article
请求内容:(请使用postman进行访问)
{
"settings": {
"number_of_replicas": 0
},
"mappings": {
"dynamic": false,
"properties": {
"publishTime": {
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"type": "date"
},
"articleCover": {
"type": "keyword"
},
"articleType": {
"type": "integer"
},
"publishUserId": {
"type": "keyword"
},
"title": {
"analyzer": "ik_smart",
"type": "text"
},
"categoryId": {
"type": "integer"
}
}
}
}
参数说明:
number_of_replicas": 0 <!-- 副本数设置为0 -->
正确返回:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "article"
}
请求方式:PUT (请使用postman进行访问)
请求地址:http://127.0.0.1:9202/xunwu
请求内容:(请使用postman进行访问)
{
"settings": {
"number_of_replicas": 0
},
"mappings": {
"dynamic": false,
"properties": {
"id": {
"type": "long"
},
"houseId": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
},
"price": {
"type": "integer"
},
"area": {
"type": "integer"
},
"createTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"lastUpdateTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"cityEnName": {
"type": "keyword"
},
"regionEnName": {
"type": "keyword"
},
"direction": {
"type": "integer"
},
"distanceToSubway": {
"type": "integer"
},
"subwayLineName": {
"type": "keyword"
},
"subwayStationName": {
"type": "keyword"
},
"tags": {
"type": "text"
},
"street": {
"type": "keyword"
},
"district": {
"type": "keyword"
},
"description": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
},
"layoutDesc" : {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
},
"traffic": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
},
"roundService": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
},
"rentWay": {
"type": "integer"
},
"suggest": {
"type": "completion"
},
"location": {
"type": "geo_point"
}
}
}
}
参数说明:
number_of_replicas": 0 <!-- 副本数设置为0 -->
正确返回:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "xunwu"
}
请求方式:DELETE (请使用postman进行访问)
请求地址:http://127.0.0.1:9202/article
正确返回:
{
"acknowledged": true
}
请求方式:GET (请使用postman进行访问)
请求地址:http://127.0.0.1:9205/rent/houseDataToEs
正确返回:
{
"code": 200,
"message": "OK",
"data": "success",
"more": false
}
(本地运行可以不申请,项目部署服务器则需要申请)
浏览器访问https://lbsyun.baidu.com/ 点击控制台 先进行个人实名认证
认证成功后进入控制台 点击 应用管理 我的应用
点击创建应用 填写以下内容 其他默认
应用名称:
xunwu-web
应用类型:
浏览器端
请求校验方式:
IP白名单校验
Referer白名单:
0.0.0.0,127.0.0.1,localhost,192.168.1.83,49.232.18.37
应用名称:
xunwu-server
应用类型:
服务端
请求校验方式:
IP白名单校验
Referer白名单:
0.0.0.0/0,0.0.0.0,127.0.0.1,49.232.18.37
将下面代码文件39行替换为刚才申请的服务器端ak
将下面代码文件90行替换为刚才申请的浏览器端ak
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型