关于Docker安装Elasticsearch和Kibana请参考:https://www.jianshu.com/p/804fe0fa6702
ik分词器github地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/,选择与Elasticsearch相同的版本,下载zip包。
进入到Docker挂载Elasticsearch的外部plugins文件夹,我的是
cd /usr/local/app/elasticsearch/plugins
没有安装过lrzsz命令的请先安装lrzsz
yum -y install lrzsz
新建并进入ik文件夹,将.zip文件上传到ik文件夹下:
mkdir ik
cd ik
输入rz,然后回车,上传.zip文件
安装unzip命令:
yum install -y unzip
解压压缩包
unzip elasticsearch-analysis-ik-7.10.1.zip
退出ik文件夹,并修改ik文件夹权限可读可写:
[root@localhost ik]# cd ..
[root@localhost plugins]# chmod -R 777 ik/
[root@localhost plugins]# cd ik
[root@localhost ik]# ll
total 5832
-rwxrwxrwx. 1 root root 263965 May 6 2018 commons-codec-1.9.jar
-rwxrwxrwx. 1 root root 61829 May 6 2018 commons-logging-1.2.jar
drwxrwxrwx. 2 root root 4096 Dec 25 2019 config
-rwxrwxrwx. 1 root root 54626 Dec 17 11:54 elasticsearch-analysis-ik-7.10.1.jar
-rwxrwxrwx. 1 root root 4504592 Jan 22 11:03 elasticsearch-analysis-ik-7.10.1.zip
-rwxrwxrwx. 1 root root 736658 May 6 2018 httpclient-4.5.2.jar
-rwxrwxrwx. 1 root root 326724 May 6 2018 httpcore-4.4.4.jar
-rwxrwxrwx. 1 root root 1807 Dec 17 11:55 plugin-descriptor.properties
-rwxrwxrwx. 1 root root 125 Dec 17 11:55 plugin-security.policy
[root@localhost ik]#
此时进入Elasticsearch容器内部
[root@localhost ik]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
169446af424e kibana:7.10.1 "/usr/local/bin/dumb…" 24 hours ago Up 55 minutes 0.0.0.0:5601->5601/tcp kibana
de9e191eef51 elasticsearch:7.10.1 "/tini -- /usr/local…" 24 hours ago Up 55 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
[root@localhost ik]# docker exec -it de9 /bin/bash
[root@de9e191eef51 elasticsearch]# ls
LICENSE.txt NOTICE.txt README.asciidoc bin config data jdk lib logs modules plugins
进入bin文件夹,执行elasticsearch-plugin命令
[root@de9e191eef51 elasticsearch]# cd bin
[root@de9e191eef51 bin]# ls
elasticsearch elasticsearch-croneval elasticsearch-migrate elasticsearch-setup-passwords elasticsearch-syskeygen x-pack-watcher-env
elasticsearch-certgen elasticsearch-env elasticsearch-node elasticsearch-shard elasticsearch-users
elasticsearch-certutil elasticsearch-env-from-file elasticsearch-plugin elasticsearch-sql-cli x-pack-env
elasticsearch-cli elasticsearch-keystore elasticsearch-saml-metadata elasticsearch-sql-cli-7.10.1.jar x-pack-security-env
[root@de9e191eef51 bin]# elasticsearch-plugin
A tool for managing installed elasticsearch plugins
Non-option arguments:
command
Option Description
------ -----------
-E Configure a setting
-h, --help Show help
-s, --silent Show minimal output
-v, --verbose Show verbose output
ERROR: Missing command
查看已安装的插件:
[root@de9e191eef51 bin]# elasticsearch-plugin list
ik
[root@de9e191eef51 bin]#
ik分词器已安装完成。
退出容器,并重启Elasticsearch
[root@de9e191eef51 bin]# exit;
exit
[root@localhost ik]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
169446af424e kibana:7.10.1 "/usr/local/bin/dumb…" 24 hours ago Up About an hour 0.0.0.0:5601->5601/tcp kibana
de9e191eef51 elasticsearch:7.10.1 "/tini -- /usr/local…" 24 hours ago Up About an hour 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
[root@localhost ik]# docker restart elasticsearch
elasticsearch
[root@localhost ik]#
进入Kibana开发工具,测试ik_smart分词器:
POST _analyze
{
"analyzer": "ik_smart",
"text": "我是中国人"
}
执行结果:
切换ik_max_word分词器:
POST _analyze
{
"analyzer": "ik_max_word",
"text": "我是中国人"
}
执行结果: