elasticsearch–ik分词器的安装

elasticsearch–ik分词器的安装

一、简介

对于中文来说,elasticsearch默认的分词器效果不太好,通常采用ik分词器。这里介绍ik分词在elasticsearch-6.2.2版本下的安装。

二、安装步骤

2.1 下载ik分词器

git clone https://github.com/medcl/elasticsearch-analysis-ik

2.2 切换匹配分支

ik版本与elasticsearch版本是需要匹配。进入分词器目录,并切换到对应elasticsearch版本的ik版本,这里对应的版本为master

cd elasticsearch-analysis-ik
git checkout master

备注:

  • 其它版本切换,如:git checkout v6.2.4

  • ik版本与elasticsearch版本对应如下:

IK version  ES version
master  6.x -> master
6.2.4  6.2.4
6.1.3  6.1.3
5.6.8  5.6.8
5.5.3  5.5.3
5.4.3  5.4.3
5.3.3  5.3.3
5.2.2  5.2.2
5.1.2  5.1.2
1.10.6  2.4.6
1.9.5  2.3.5
1.8.1  2.2.1
1.7.0  2.1.1
1.5.0  2.0.0
1.2.6  1.0.0
1.2.5  0.90.x
1.1.3  0.20.x
1.0.0  0.16.2 -> 0.19.0

2.3 通过maven打包

mvn clean package -Dmaven.skip.test=true

2.4 解压打好的包

解压打包好的elasticsearch-analysis-ik-6.2.4.zip文件

unzip target/releases/elasticsearch-analysis-ik-6.2.4.zip

2.5 配置ik分词器

将解压文件复制到elasticsearch的plugin目录下,重命名为ik

mv target/releases/elasticsearch ~/programs/elasticsearch/plugins/ik

2.6 重启elasticsearch

bin/elasticsearch

至此在elasticsearch中,ik分词器安装完成。

三、使用

Analyzer: ik_smart , ik_max_word ;

Tokenizer: ik_smart , ik_max_word。

ik分词器有两种,即ik_max_word 和 ik_smart,ik_max_word是进行最细粒度的切分,而ik_smart是用粗粒度切分。

请求例如:

curl -s -XGET "${host}:${port}/${index}/_analyze?pretty" -H 'Content-Type: application/json' -d'
{
   "text":"好好学习,天天向上","tokenizer": "ik_max_word"
}'

在创建mapping时,可以指定分词器,如:

curl -s -XPOST http://localhost:9200/index/type/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
}'
发布了274 篇原创文章 · 获赞 95 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/chinabestchina/article/details/104933713