ES-IK中文分词器安装
日期:2019-10-23
环境:CentOS 7.2
续接文档:ES安装、注意点(Elasticsearch 7.3.2)
1. 准备安装包
重点:一定要与ES的版本一致(本文版本:7.3.2)
项目地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.3.2/elasticsearch-analysis-ik-7.3.2.zip
2. 下载并解压
cd /usr/local/es
#下载
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.3.2/elasticsearch-analysis-ik-7.3.2.zip
#解压
unzip elasticsearch-analysis-ik-7.3.2.zip
3. 安装
将 ik 的压缩包解压到 ES安装目录的plugins/目录下(最好把解出的目录名改一下,防止安装别的插件时同名冲突)
cd /usr/local/es
#移动 ik 插件到 es 的 plugins 目录
mv elasticsearch-analysis-ik-7.3.2 /usr/local/es/elasticsearch-7.3.2/plugins/ik
4. 重启ES
5. 扩展词库
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">custom/ext_stopword.dic</entry>
<!--用户可以在这里配置远程扩展字典 远程词库,可热更新,在一处地方维护-->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
6. 测试IK
- 创建一个索引
#ES7的创建方式
PUT http://192.168.1.92:9200/iktest
{
"mappings":{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
#另外一种请求方式
curl -X PUT http://172.18.178.199:9200/iktest -H "Content-type: application/json" -d'
{
"mappings":{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
'
- 分词测试
POST http://192.168.1.92:9200/_analyze
{
"analyzer":"ik_smart",
"text":"天团S.H.E昨在两厅院艺文广场举办17万人露天音乐会,3人献唱多首经典好歌,让现场粉丝听得如痴如醉"
}
curl -X POST http://172.18.178.199:9200/_analyze -H "Content-type: application/json" -d'
{
"analyzer":"ik_smart",
"text":"天团S.H.E昨在两厅院艺文广场举办17万人露天音乐会,3人献唱多首经典好歌,让现场粉丝听得如痴如醉"
}
'
- 对比standard分词器
POST http://192.168.1.92:9200/_analyze
{
"analyzer":"standard",
"text":"天团S.H.E昨在两厅院艺文广场举办17万人露天音乐会,3人献唱多首经典好歌,让现场粉丝听得如痴如醉"
}