ElasticSearch 实现分词全文检索 – ES、Kibana、IK安装
目录
ElasticSearch 实现分词全文检索 – 概述
ElasticSearch 实现分词全文检索 – ES、Kibana、IK安装
ElasticSearch 实现分词全文检索 – Restful基本操作 –待发布
ElasticSearch 实现分词全文检索 – Java SpringBoot ES 索引操作 –待发布
ElasticSearch 实现分词全文检索 – Java SpringBoot ES 文档操作 –待发布
ElasticSearch 实现分词全文检索 – 测试数据准备 –待发布
ElasticSearch 实现分词全文检索 – term、terms查询 –待发布
ElasticSearch 实现分词全文检索 – id、ids、prefix、fuzzy、wildcard、range、regexp 查询 –待发布
ElasticSearch 实现分词全文检索 – Scroll 深分页 –待发布
ElasticSearch 实现分词全文检索 – delete-by-query –待发布
ElasticSearch 实现分词全文检索 – 复合查询 –待发布
ElasticSearch 实现分词全文检索 – filter查询 –待发布
ElasticSearch 实现分词全文检索 – 高亮查询 –待发布
ElasticSearch 实现分词全文检索 – 聚合查询 cardinality –待发布
ElasticSearch 实现分词全文检索 – 经纬度查询 –待发布
安装 ElasticSearch
详见 Docker 安装 Elasticsearch、Kibana 7.9.3
或者 使用 docker compose 安装
[root@localhost elasticsearch]# pwd
/opt/elasticsearch
#安装
[root@localhost elasticsearch]# docker-compose up -d
#查看日志
[root@localhost elasticsearch]# docker-compose logs -f
docker-compose.yml
version:
services:
elasticsearch:
image: daocloud.io/library/elasticsearch:7.9.3
restart: always
container_name: elasticsearch
ports:
-9200:9200
kibana:
image: daocloud.io/library/kibana:7.9.3
restart: always
container name: kibana
ports:
- 5601:5601
environment:
- elasticsearch url=http://172.16.3.88:9200
depends_on:
- elasticsearch
安装 IK Analysis
ES 默认分词器,对汉字的分词不太友好
下载 ik 分词器插件
找到对应的 Elasticsearch 版本,这里用的:7.9.3,将地址复制到讯雷里下,直接下的话下不动
https://elasticsearch.cn/download/
方式一:在容器中下载安装
先把zip下载下来。放到任意一台服务器(直接github上下载多数会失败)
# 查看 ES 的容器ID
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad684997e228 elasticsearch:7.9.3 "/tini -- /usr/local…" 7 minutes ago Up 7 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
# 进入 ES 容器
[root@localhost ~]# docker exec -it ad68 /bin/bash
# 通过命令进行 ElasticSearch 插件安装,不需要重启
[root@ad684997e228 elasticsearch]# elasticsearch-plugin install http://172.16.0.66/elasticsearch-analysis-ik-7.9.3.zip
-> Downloading http://172.16.0.66/elasticsearch-analysis-ik-7.9.3.zip
[=================================================] 100%??
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.
Continue with installation? [y/N]y
-> Installed analysis-ik
[root@ad684997e228 elasticsearch]#
方式二:将文件上传至容器,进行安装
将 ik 文件传至服务器
将 ik 复制到容器,并安装
# 查看 ES 的容器ID
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad684997e228 elasticsearch:7.9.3 "/tini -- /usr/local…" 7 minutes ago Up 7 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
# 将it 插件,复制到容器中
[root@localhost ~]# docker cp /opt/elasticsearch-analysis-ik-7.9.3.zip ad684997e228:/usr/share/elasticsearch
# 进入 ES 容器
[root@localhost ~]# docker exec -it ad68 /bin/bash
# 通过命令进行 ElasticSearch 插件安装,不需要重启
[root@ad684997e228 elasticsearch]# elasticsearch-plugin install file:/usr/share/elasticsearch/elasticsearch-analysis-ik-7.9.3.zip
-> Installing file:/usr/share/elasticsearch/elasticsearch-analysis-ik-7.9.3.zip
-> Downloading file:/usr/share/elasticsearch/elasticsearch-analysis-ik-7.9.3.zip
[=================================================] 100%??
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.
Continue with installation? [y/N]y
-> Installed analysis-ik
[root@ad684997e228 elasticsearch]#
重启容器
docker restart xxx
如果不重启会报:failed to find global analyzer [ik_smart]
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "failed to find global analyzer [ik_smart]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to find global analyzer [ik_smart]"
},
"status": 400
}
接口测试(Postman)
http://172.16.3.88:9200/_analyze
{
"analyzer":"ik_smart",
"text":"心脏搭桥手术"
}
Kibana 测试
POST _analyze
{
"analyzer":"ik_smart",
"text":"心脏搭桥手术"
}