Elastic Search中文分词器IK简介:

Elastic Search默认不支持中文分词,所有的语言分词,默认使用的都是**“Standard Analyzer”**。因此我们需要为我们的Elastic Search集成开源的IK中文分词器
IK分词器的GitHub地址:https://github.com/medcl/elasticsearch-analysis-ik

是一位国人作者,以下是作者的简介:
image

1、IK分词器安装

IK版本严格按照官方给出与Elastic Search对应的版本,可在IK分词器的GitHub官网在查看

1.1、查询当前安装的Elastic Search版本

在前面安装的elasticsearch时,我们已经将elasticsearch容器的“/usr/share/elasticsearch/plugins”目录,映射到宿主机的“ /mydata/elasticsearch/plugins”目录下,所以比较方便的做法就是下载“/elasticsearch-analysis-ik-7.4.2.zip”文件,然后解压到该文件夹下即可。安装完毕后,需要重启elasticsearch容器。

  • docker exec -it 容器id /bin/bash
[root@a2994edc234b plugins]# curl http://localhost:9200
{
  "name" : "a2994edc234b",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "LbMkqgufRxaJd7PiO2JaeA",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

我的version 7.4.2

1.2、进入es容器内部plugin目录

[root@a2994edc234b plugins]# wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip


--2021-06-09 14:59:50--  https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/2993595/19827980-fef3-11e9-8cda-384bc0d9396c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210609%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210609T145956Z&X-Amz-Expires=300&X-Amz-Signature=8ead0d069104aa8433594e2435fbb7d572eab8fdf813a16bf6b8005f81787aae&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=2993595&response-content-disposition=attachment%3B%20filename%3Delasticsearch-analysis-ik-7.4.2.zip&response-content-type=application%2Foctet-stream [following]
--2021-06-09 14:59:57--  https://github-releases.githubusercontent.com/2993595/19827980-fef3-11e9-8cda-384bc0d9396c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210609%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210609T145956Z&X-Amz-Expires=300&X-Amz-Signature=8ead0d069104aa8433594e2435fbb7d572eab8fdf813a16bf6b8005f81787aae&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=2993595&response-content-disposition=attachment%3B%20filename%3Delasticsearch-analysis-ik-7.4.2.zip&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.111.154, 185.199.110.154, 185.199.109.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.111.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4504487 (4.3M) [application/octet-stream]
Saving to: 'elasticsearch-analysis-ik-7.4.2.zip'

100%[=======================================================================================================================================================>] 4,504,487   47.7KB/s   in 94s    

2021-06-09 15:01:31 (47.0 KB/s) - 'elasticsearch-analysis-ik-7.4.2.zip' saved [4504487/4504487]

看到以上提示,恭喜你下载Ik分词器成功!
以上wgetGitHub上下载,如果网络不好的 可以到官方下载zip安装包

1、3解压IK分词器到ik目录

  • unzip elasticsearch-analysis-ik-7.4.2.zip -d ik
[root@a2994edc234b plugins]# unzip elasticsearch-analysis-ik-7.4.2.zip -d ik

Archive:  elasticsearch-analysis-ik-7.4.2.zip
  inflating: ik/elasticsearch-analysis-ik-7.4.2.jar  
  inflating: ik/httpclient-4.5.2.jar  
  inflating: ik/httpcore-4.4.4.jar   
  inflating: ik/commons-logging-1.2.jar  
  inflating: ik/commons-codec-1.9.jar  
  inflating: ik/plugin-descriptor.properties  
  inflating: ik/plugin-security.policy  
   creating: ik/config/
  inflating: ik/config/surname.dic   
  inflating: ik/config/quantifier.dic  
  inflating: ik/config/extra_stopword.dic  
  inflating: ik/config/suffix.dic    
  inflating: ik/config/extra_single_word_full.dic  
  inflating: ik/config/extra_single_word.dic  
  inflating: ik/config/preposition.dic  
  inflating: ik/config/IKAnalyzer.cfg.xml  
  inflating: ik/config/main.dic      
  inflating: ik/config/stopword.dic  
  inflating: ik/config/extra_main.dic  
  inflating: ik/config/extra_single_word_low_freq.dic  

[root@a2994edc234b plugins]# ls
elasticsearch-analysis-ik-7.4.2.zip  ik
[root@a2994edc234b plugins]# chmod -R 777 ik/ #赋予ik权限
[root@a2994edc234b plugins]# rm -rf  elasticsearch-analysis-ik-7.4.2.zip 

1.4安装好之后重启docker的Elastic Search容器

[root@a2994edc234b plugins]# docker restart elasticsearch

image

大功告成!