最近在学习使用elasticsearch,但是在安装插件ik的时候遇到许多问题。
所以在这里开始对elasticsearch做一个深度的研究。
首先提供如下链接:
https://github.com/infinilabs/analysis-ik/releases
我们下载elasticsearch-7-17-2的Linux x86_64版本
链接:
https://www.elastic.co/downloads/past-releases/elasticsearch-7-17-2
打开文件:
![](https://i-blog.csdnimg.cn/direct/cb9832ffea634ecb8c7b80d0d6215182.png)
![](https://i-blog.csdnimg.cn/direct/bb4006d272044d6496ad6a58223142ad.png)
然后我们在docker中安装elasticsearch-7-17-2并进入容器:
python
docker pull elasticsearch:7.17.2
python
docker run -d \
--name es \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
--privileged \
--network hm-net \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:7.17.2
python
docker exec -it es bash
可以看到
python
root@06118690fede:/usr/share/elasticsearch# ll
total 644
drwxrwxr-x. 1 root root 58 Feb 6 21:01 ./
drwxr-xr-x. 1 root root 27 Mar 28 2022 ../
-rw-r--r--. 1 root root 220 Mar 28 2022 .bash_logout
-rw-r--r--. 1 root root 3771 Mar 28 2022 .bashrc
drwxrwxr-x. 3 elasticsearch root 17 Feb 6 21:01 .cache/
-rw-r--r--. 1 root root 807 Mar 28 2022 .profile
-r--r--r--. 1 root root 3860 Mar 28 2022 LICENSE.txt
-r--r--r--. 1 root root 627787 Mar 28 2022 NOTICE.txt
-r--r--r--. 1 root root 2710 Mar 28 2022 README.asciidoc
drwxrwxr-x. 1 elasticsearch root 6 Mar 28 2022 bin/
drwxrwxr-x. 1 elasticsearch root 36 Feb 6 21:01 config/
drwxrwxr-x. 1 elasticsearch root 19 Feb 6 21:01 data/
dr-xr-xr-x. 1 root root 17 Mar 28 2022 jdk/
dr-xr-xr-x. 3 root root 4096 Mar 28 2022 lib/
drwxrwxr-x. 1 elasticsearch root 37 Feb 6 21:01 logs/
dr-xr-xr-x. 61 root root 4096 Mar 28 2022 modules/
drwxrwxr-x. 1 elasticsearch root 6 Mar 28 2022 plugins/
root@06118690fede:/usr/share/elasticsearch# ll config/
total 56
drwxrwxr-x. 1 elasticsearch root 36 Feb 6 21:01 ./
drwxrwxr-x. 1 root root 58 Feb 6 21:01 ../
-rw-rw-r--. 1 root root 1042 Mar 28 2022 elasticsearch-plugins.example.yml
-rw-rw----. 1 elasticsearch root 199 Feb 6 21:01 elasticsearch.keystore
-rw-rw-r--. 1 root root 53 Mar 28 2022 elasticsearch.yml
-rw-rw-r--. 1 root root 3257 Mar 28 2022 jvm.options
drwxrwxr-x. 1 elasticsearch root 6 Mar 28 2022 jvm.options.d/
-rw-rw-r--. 1 root root 19304 Mar 28 2022 log4j2.file.properties
-rw-rw-r--. 1 root root 10643 Mar 28 2022 log4j2.properties
-rw-rw-r--. 1 root root 473 Mar 28 2022 role_mapping.yml
-rw-rw-r--. 1 root root 197 Mar 28 2022 roles.yml
-rw-rw-r--. 1 root root 0 Mar 28 2022 users
-rw-rw-r--. 1 root root 0 Mar 28 2022 users_roles
root@06118690fede:/usr/share/elasticsearch# ll plugins/
total 0
drwxrwxr-x. 1 elasticsearch root 6 Mar 28 2022 ./
drwxrwxr-x. 1 root root 58 Feb 6 21:01 ../
与我们在windows上打开的,可以看到,基本上内容是一样的。
随后我们安装插件ik:
python
# 在容器内
bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/7.17.2
# 这里的链接的来源是:https://github.com/infinilabs/analysis-ik/releases
![](https://i-blog.csdnimg.cn/direct/f98e136d1352449a80234e44cf65424c.png)
随后,我们再来查看文件系统:
python
root@06118690fede:/usr/share/elasticsearch# ll
total 644
drwxrwxr-x. 1 root root 73 Feb 6 21:01 ./
drwxr-xr-x. 1 root root 27 Mar 28 2022 ../
-rw-r--r--. 1 root root 220 Mar 28 2022 .bash_logout
-rw-r--r--. 1 root root 3771 Mar 28 2022 .bashrc
drwxrwxr-x. 3 elasticsearch root 17 Feb 6 21:01 .cache/
-rw-r--r--. 1 root root 807 Mar 28 2022 .profile
-r--r--r--. 1 root root 3860 Mar 28 2022 LICENSE.txt
-r--r--r--. 1 root root 627787 Mar 28 2022 NOTICE.txt
-r--r--r--. 1 root root 2710 Mar 28 2022 README.asciidoc
drwxrwxr-x. 1 elasticsearch root 6 Mar 28 2022 bin/
drwxrwxr-x. 1 elasticsearch root 55 Feb 6 21:10 config/
drwxrwxr-x. 1 elasticsearch root 19 Feb 6 21:01 data/
dr-xr-xr-x. 1 root root 17 Mar 28 2022 jdk/
dr-xr-xr-x. 3 root root 4096 Mar 28 2022 lib/
drwxrwxr-x. 1 elasticsearch root 37 Feb 6 21:01 logs/
dr-xr-xr-x. 61 root root 4096 Mar 28 2022 modules/
drwxrwxr-x. 1 elasticsearch root 25 Feb 6 21:10 plugins/
root@06118690fede:/usr/share/elasticsearch# ll config/
total 60
drwxrwxr-x. 1 elasticsearch root 55 Feb 6 21:10 ./
drwxrwxr-x. 1 root root 73 Feb 6 21:01 ../
drwxr-x---. 2 elasticsearch root 4096 Feb 6 21:10 analysis-ik/
-rw-rw-r--. 1 root root 1042 Mar 28 2022 elasticsearch-plugins.example.yml
-rw-rw----. 1 elasticsearch root 199 Feb 6 21:01 elasticsearch.keystore
-rw-rw-r--. 1 root root 53 Mar 28 2022 elasticsearch.yml
-rw-rw-r--. 1 root root 3257 Mar 28 2022 jvm.options
drwxrwxr-x. 1 elasticsearch root 6 Mar 28 2022 jvm.options.d/
-rw-rw-r--. 1 root root 19304 Mar 28 2022 log4j2.file.properties
-rw-rw-r--. 1 root root 10643 Mar 28 2022 log4j2.properties
-rw-rw-r--. 1 root root 473 Mar 28 2022 role_mapping.yml
-rw-rw-r--. 1 root root 197 Mar 28 2022 roles.yml
-rw-rw-r--. 1 root root 0 Mar 28 2022 users
-rw-rw-r--. 1 root root 0 Mar 28 2022 users_roles
root@06118690fede:/usr/share/elasticsearch# ll plugins/
total 0
drwxrwxr-x. 1 elasticsearch root 25 Feb 6 21:10 ./
drwxrwxr-x. 1 root root 73 Feb 6 21:01 ../
drwxr-xr-x. 2 root root 230 Feb 6 21:10 analysis-ik/
root@06118690fede:/usr/share/elasticsearch# ll config/analysis-ik/
total 8264
drwxr-x---. 2 elasticsearch root 4096 Feb 6 21:10 ./
drwxrwxr-x. 1 elasticsearch root 55 Feb 6 21:10 ../
-rw-rw----. 1 elasticsearch root 625 Feb 6 21:10 IKAnalyzer.cfg.xml
-rw-rw----. 1 elasticsearch root 5225922 Feb 6 21:10 extra_main.dic
-rw-rw----. 1 elasticsearch root 63188 Feb 6 21:10 extra_single_word.dic
-rw-rw----. 1 elasticsearch root 63188 Feb 6 21:10 extra_single_word_full.dic
-rw-rw----. 1 elasticsearch root 10855 Feb 6 21:10 extra_single_word_low_freq.dic
-rw-rw----. 1 elasticsearch root 156 Feb 6 21:10 extra_stopword.dic
-rw-rw----. 1 elasticsearch root 3058510 Feb 6 21:10 main.dic
-rw-rw----. 1 elasticsearch root 123 Feb 6 21:10 preposition.dic
-rw-rw----. 1 elasticsearch root 1824 Feb 6 21:10 quantifier.dic
-rw-rw----. 1 elasticsearch root 164 Feb 6 21:10 stopword.dic
-rw-rw----. 1 elasticsearch root 192 Feb 6 21:10 suffix.dic
-rw-rw----. 1 elasticsearch root 752 Feb 6 21:10 surname.dic
root@06118690fede:/usr/share/elasticsearch# ll plugins/analysis-ik/
total 1428
drwxr-xr-x. 2 root root 230 Feb 6 21:10 ./
drwxrwxr-x. 1 elasticsearch root 25 Feb 6 21:10 ../
-rw-r--r--. 1 root root 263965 Feb 6 21:10 commons-codec-1.9.jar
-rw-r--r--. 1 root root 61829 Feb 6 21:10 commons-logging-1.2.jar
-rw-r--r--. 1 root root 54953 Feb 6 21:10 elasticsearch-analysis-ik-7.17.2.jar
-rw-r--r--. 1 root root 736658 Feb 6 21:10 httpclient-4.5.2.jar
-rw-r--r--. 1 root root 326724 Feb 6 21:10 httpcore-4.4.4.jar
-rw-r--r--. 1 root root 1807 Feb 6 21:10 plugin-descriptor.properties
-rw-r--r--. 1 root root 125 Feb 6 21:10 plugin-security.policy
root@06118690fede:/usr/share/elasticsearch#
我们在config/analysis-ik/中找到了IKAnalyzer.cfg.xml文件。
闹麻了,TMD配置是在这个位置。
然后在这个IKAnalyzer.cfg.xml文件中自定义自己的分词器。