本篇笔记记录了ElasticSearch安装中文分词插件IK Analysis,测试分词和测试搜索的过程
相关笔记:
CentOS6.9使用RPM包安装ElasticSearch
CentOS6.9安装ElasticSearch
安装IK
方法1:下载预编译包
wget -c https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.6.0/elasticsearch-analysis-ik-6.6.0.zip
创建插件文件夹 cd your-es-root/plugins/ && mkdir ik
将插件解压缩到文件夹 your-es-root/plugins/ik
方法2:使用elasticsearch-plugin进行安装(从v5.5.1版本支持)
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.6.0/elasticsearch-analysis-ik-6.6.0.zip
安装后重启elasticsearch
service elasticsearch restart
分词测试
创建一个索引
curl -XPUT http://192.168.75.135:9200/ikindex
创建一个映射模版
curl -XPOST http://192.168.75.135:9200/ikindex/iktype/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
默认分词测试
curl -XGET http://192.168.75.135:9200/ikindex/_analyze?pretty=true -H 'Content-Type:application/json' -d'{"text":"我的学习笔记"}'
{
"tokens" : [
{
"token" : "我",
"start_offset" : 0,
"end_offset" : 1,
"type" : "<IDEOGRAPHIC>",
"position" : 0
},
{
"token"