ES常用的分词器有StandardAnalyzer、ChineseAnalyzer、CJKAnalyze、IKAnalyzer等,其中IK词库分词是第三方插件,对中文支持尚可,也是本文介绍的、实践过程中用到的分词器。
第三方插件需要安装,IK分词器插件安装版本要与ES版本一致,否则容易不兼容。
集成方式超级简单,从GIT上下载IK分词器插件,并拷贝至ES的plugin文件夹下,启动ES,即OK。
加载插件成功截图如下:
验证集成效果:
1、用标准分词器
GET http://127.0.0.1:9200/_analyze?analyzer=standard&pretty=true&text=学习Elasticsearch
响应为:
{
"tokens": [
{
"token": "学",
"start_offset": 0,
"end_offset": 1,
"type": "<IDEOGRAPHIC>",
"position": 0
},
{
"token": "习",
"start_offset": 1,
"end_offset": 2,
"type": "<IDEOGRAPHIC>",
"position": 1
},
{
"token": "elasticsearch",
"start_offset": 2,
"end_offset": 15,
"type": "<ALPHANUM>",
"position": 2
}
]
}
2、用IK分词器
GET http://127.0.0.1:9200/_analyze?analyzer=ik_smart&pretty=true&text=学习Elasticsearch
响应为:
{
"tokens": [
{
"token": "学习",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "elasticsearch",
"start_offset": 2,
"end_offset": 15,
"type": "ENGLISH",
"position": 1
}
]
}