进入安装目录
/home/data/appcom/elasticsearch-6.6.2/bin/elasticsearch-plugin
在github上找到releases与Elasticsearch对应的版本
执行
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.6.2/elasticsearch-analysis-ik-6.6.2.zip
等待一段时间久可以安装成功。
一般情况下可能会出现网络异常的情况,重新执行一遍。就可以。
出现这个说明安装成功。每一个节点都需要安装。
安装后需要重新启动Elasticsearch。否则分词器不生效。
测试
默认分词器
GET _analyze?pretty
{
"analyzer": "default",
"text": "中国人有长城防火墙,中国人很爱中国"
}
结果
{
"tokens" : [
{
"token" : "中",
"start_offset" : 0,
"end_offset" : 1,
"type" : "<IDEOGRAPHIC>",
"position" : 0
},
{
"token" : "国",
"start_offset" : 1,
"end_offset" : 2,
"type" : "<IDEOGRAPHIC>",
"position" : 1
},
{
"token" : "人",
"start_offset" : 2,
"end_offset" : 3,
"type" : "<IDEOGRAPHIC>",
"position" : 2
},
{
"token" : "有",
"start_offset" : 3,
"end_offset" : 4,
"type" : "<IDEOGRAPHIC>",
"position" : 3
},
{
"token" : "长",
"start_offset" : 4,
"end_offset" : 5,
"type" : "<IDEOGRAPHIC>",
"position" : 4
},
{
"token" : "城",
"start_offset" : 5,
"end_offset" : 6,
"type" : "<IDEOGRAPHIC>",
"position" : 5
},
{
"token" : "防",
"start_offset" : 6,
"end_offset" : 7,
"type" : "<IDEOGRAPHIC>",
"position" : 6
},
{
"token" : "火",
"start_offset" : 7,
"end_offset" : 8,
"type" : "<IDEOGRAPHIC>",
"position" : 7
},
{
"token" : "墙",
"start_offset" : 8,
"end_offset" : 9,
"type" : "<IDEOGRAPHIC>",
"position" : 8
},
{
"token" : "中",
"start_offset" : 10,
"end_offset" : 11,
"type" : "<IDEOGRAPHIC>",
"position" : 9
},
{
"token" : "国",
"start_offset" : 11,
"end_offset" : 12,
"type" : "<IDEOGRAPHIC>",
"position" : 10
},
{
"token" : "人",
"start_offset" : 12,
"end_offset" : 13,
"type" : "<IDEOGRAPHIC>",
"position" : 11
},
{
"token" : "很",
"start_offset" : 13,
"end_offset" : 14,
"type" : "<IDEOGRAPHIC>",
"position" : 12
},
{
"token" : "爱",
"start_offset" : 14,
"end_offset" : 15,
"type" : "<IDEOGRAPHIC>",
"position" : 13
},
{
"token" : "中",
"start_offset" : 15,
"end_offset" : 16,
"type" : "<IDEOGRAPHIC>",
"position" : 14
},
{
"token" : "国",
"start_offset" : 16,
"end_offset" : 17,
"type" : "<IDEOGRAPHIC>",
"position" : 15
}
]
}
GET _analyze?pretty
{
"analyzer": "ik_smart",
"text": "中国人有长城防火墙,中国人很爱中国"
}
结果
{
"tokens" : [
{
"token" : "中国人",
"start_offset" : 0,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "有",
"start_offset" : 3,
"end_offset" : 4,
"type" : "CN_CHAR",
"position" : 1
},
{
"token" : "长城",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "防火墙",
"start_offset" : 6,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 3
},
{
"token" : "中国人",
"start_offset" : 10,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 4
},
{
"token" : "很爱",
"start_offset" : 13,
"end_offset" : 15,
"type" : "CN_WORD",
"position" : 5
},
{
"token" : "中国",
"start_offset" : 15,
"end_offset" : 17,
"type" : "CN_WORD",
"position" : 6
}
]
}