ElasticSearch集成个性化中文分词插件

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
    }
  ]
}
发布了27 篇原创文章 · 获赞 17 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/pharos/article/details/105811032
今日推荐