Java小强个人技术博客站点    手机版
当前位置: 首页 >> 软件 >> Elasticsearch安装IK分词器

Elasticsearch安装IK分词器

21820 软件 | 2022-2-9

Elasticsearch 是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。 作为 Elastic Stack 的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况。


Centos上通过Docker安装单节点ES http://www.javacui.com/628.html 

Centos上通过Docker安装ES管理端kibana http://www.javacui.com/tool/629.html 

下载与文档,这里是国内代理节点 https://gitcode.net/mirrors/medcl/elasticsearch-analysis-ik 

或官方 https://github.com/medcl/elasticsearch-analysis-ik


在线安装

# 进入容器内部
docker exec -it es /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 es


离线安装

查看ES插件目录

docker volume inspect es-plugins

输出

[
    {
        "CreatedAt": "2022-02-08T23:16:54+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 `这个目录中


解压缩分词器安装包,重命名为ik

上传到es容器的插件数据卷中,也就是/var/lib/docker/volumes/es-plugins/_data


进入容器拷贝插件到运行目录

docker exec -it es /bin/bash
/usr/local/elasticsearch/data
cp -r ik /usr/share/elasticsearch/plugins

为什么没有直接邦定这个目录?因为实际使用中发现,es在容器内的运行目录是

docker exec -it es /bin/bash
curl "localhost:9200/_nodes/settings?pretty=true"
# 示例settings.path.home值 /usr/share/elasticsearch

但是创建容器时不能直接指定到该目录,原因暂时未知,所以这里先折中完成目的,后期再研究具体原因。


# 重启容器
docker restart es
# 查看启动日志
docker logs -f es


说明:

IK分词器包含两种模式:

`ik_smart`:最少切分

`ik_max_word`:最细切分


测试

GET /_analyze
{
  "analyzer": "ik_max_word",
  "text": "中华人民共和国万岁"
}
GET /_analyze
{
  "analyzer": "ik_smart",
  "text": "中华人民共和国万岁"
}


其他分词器

mmseg4j https://gitee.com/mirrors/mmseg4j 

paoding http://code.google.com/p/paoding/ 


推荐您阅读更多有关于“ linux CentOS Docker elasticsearch 分词器 ik ”的文章

上一篇:IK分词器扩展词停用词 下一篇:Centos上通过Docker安装ES管理端kibana

猜你喜欢

发表评论: