.安装IK分词器
1.在线安装ik插件(较慢)
# 进入容器内部 docker exec -it elasticsearch /bin/bash  # 在线下载并安装 ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip  #退出 exit #重启容器 docker restart elasticsearch
2.离线安装ik插件(推荐)
1)查看数据卷目录
安装插件需要知道elasticsearch的plugins目录位置,而我们用了数据卷挂载,因此需要查看elasticsearch的数据卷目录,通过下面命令查看:
docker volume inspect es-plugins
显示结果:
[
    {
        "CreatedAt": "2022-05-06T10:06:34+08:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/es-plugins/_data",
        "Name": "es-plugins",
        "Options": null,
        "Scope": "local"
    }
] 
说明plugins目录被挂载到了:/var/lib/docker/volumes/es-plugins/_data这个目录中。
2)解压缩分词器安装包
下面我们需要把课前资料中的ik分词器解压缩,重命名为ik
链接:https://pan.baidu.com/s/1KLi71wyX4Znq7GE0jCRUUg?pwd=a3km 
 提取码:a3km
3)上传到es容器的插件数据卷中
也就是/var/lib/docker/volumes/es-plugins/_data:
把解压的文件拉到数据卷中:

4)重启容器
# 4、重启容器 docker restart es
# 查看es日志 docker logs -f es
5)测试:
IK分词器包含两种模式:
-  
ik_smart:最少切分 -  
ik_max_word:最细切分 
GET /_analyze
{
 "analyzer": "ik_max_word",
 "text": "北京欢迎你我家大门常打开"
} 
结果:
{
  "tokens" : [
    {
      "token" : "北京",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "欢迎",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "你我",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "我家",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "大门",
      "start_offset" : 7,
      "end_offset" : 9,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "常打",
      "start_offset" : 9,
      "end_offset" : 11,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "打开",
      "start_offset" : 10,
      "end_offset" : 12,
      "type" : "CN_WORD",
      "position" : 6
    }
  ]
} 
扩展词词典和停用词词典
1)打开IK分词器config目录:

2)在IKAnalyzer.cfg.xml配置文件内容添加并创建文件:

3)重启elasticsearch
docker restart es
完事



![[Docker] Docker为什么出现](https://img-blog.csdnimg.cn/direct/eb8c99a6ce3049ea8d0d7a26c5f8ed28.png)















