本篇文章为大家展示了elasticsearch 5.x中IK分词器怎么用,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
ik分词器的地址 https://github.com/medcl/elasticsearch-analysis-ik/releases ,分词器插件需要和ES版本匹配
由于es是5.6.16版本,所有我们下载5.6.16
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.16/elasticsearch-analysis-ik-5.6.16.zip
解压后,把安装包放在ES节点的plugins目录,包名重命名为ik
重启ES,测试下IK分词效果
(1)无分词器下的效果
GET _analyze?pretty { "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 } ] }
可见 “安徽省长江流域” 每个字都分成了一个词
(2)IK分词器下的效果,ik_smart分词器
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": 7, "type": "CN_WORD", "position": 1 } ] }
(3)IK分词器下的效果,ik_smart分词器
GET _analyze?pretty { "analyzer": "ik_max_word", "text":"安徽省长江流域" }
结果
{ "tokens": [ { "token": "安徽省", "start_offset": 0, "end_offset": 3, "type": "CN_WORD", "position": 0 }, { "token": "安徽", "start_offset": 0, "end_offset": 2, "type": "CN_WORD", "position": 1 }, { "token": "省长", "start_offset": 2, "end_offset": 4, "type": "CN_WORD", "position": 2 }, { "token": "长江流域", "start_offset": 3, "end_offset": 7, "type": "CN_WORD", "position": 3 }, { "token": "长江", "start_offset": 3, "end_offset": 5, "type": "CN_WORD", "position": 4 }, { "token": "江流", "start_offset": 4, "end_offset": 6, "type": "CN_WORD", "position": 5 }, { "token": "流域", "start_offset": 5, "end_offset": 7, "type": "CN_WORD", "position": 6 } ] }
为什么IK分词器能分析中文词汇呢?因为在它的config目录内置了一些词典。
那么如果我们需要识别一些新的词汇怎么办?例如一部连续剧 “权利的游戏”
自定义词典
在IK插件的config目录下创建tv目录,新建 tv.dic 文件(注意,一定要UTF-8无BOM的格式)
然后在 IKAnalyzer.cfg.xml 文件在添加配置
重启ES、Kibana ,试下效果
GET _analyze?pretty { "analyzer": "ik_smart", "text":"权利的游戏" }
分词结果
{ "tokens": [ { "token": "权利的游戏", "start_offset": 0, "end_offset": 5, "type": "CN_WORD", "position": 0 } ] }
上述内容就是elasticsearch 5.x中IK分词器怎么用,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。