前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Elasticsearch下安装IK中文分词器

Elasticsearch下安装IK中文分词器

作者头像
Stanley Sun
发布2019-09-23 15:21:15
5510
发布2019-09-23 15:21:15
举报
文章被收录于专栏:思考是一种快乐

环境:elasticsearch版本是5.5.2,其所在目录为/usr/local/elasticsearch-5.5.2

  1. 下载

解压到 /usr/local/elasticsearch-5.5.2/plugins/ , 目录结构如下

代码语言:javascript
复制
├── plugins
│   └── elasticsearch-analysis-ik
│       ├── commons-codec-1.9.jar
│       ├── commons-logging-1.2.jar
│       ├── config
│       │   ├── extra_main.dic
│       │   ├── extra_single_word.dic
│       │   ├── extra_single_word_full.dic
│       │   ├── extra_single_word_low_freq.dic
│       │   ├── extra_stopword.dic
│       │   ├── IKAnalyzer.cfg.xml
│       │   ├── main.dic
│       │   ├── preposition.dic
│       │   ├── quantifier.dic
│       │   ├── stopword.dic
│       │   ├── suffix.dic
│       │   └── surname.dic
│       ├── elasticsearch-analysis-ik-5.5.2.jar
│       ├── httpclient-4.5.2.jar
│       ├── httpcore-4.4.4.jar
│       └── plugin-descriptor.properties
  1. 重启 elasticsearch
  2. 测试

分别用下面两种方式检查一下分词效果

ik_max_word分词法

代码语言:javascript
复制
GET _analyze
{
  "analyzer":"ik_max_word",
  "text":"中华人民共和国国歌"
}

结果

代码语言:javascript
复制
{
  "tokens": [
    {
      "token": "中华人民共和国",
      "start_offset": 0,
      "end_offset": 7,
      "type": "CN_WORD",
      "position": 0
    },
    {
      "token": "中华人民",
      "start_offset": 0,
      "end_offset": 4,
      "type": "CN_WORD",
      "position": 1
    },
    {
      "token": "中华",
      "start_offset": 0,
      "end_offset": 2,
      "type": "CN_WORD",
      "position": 2
    },
    {
      "token": "华人",
      "start_offset": 1,
      "end_offset": 3,
      "type": "CN_WORD",
      "position": 3
    },
    {
      "token": "人民共和国",
      "start_offset": 2,
      "end_offset": 7,
      "type": "CN_WORD",
      "position": 4
    },
    {
      "token": "人民",
      "start_offset": 2,
      "end_offset": 4,
      "type": "CN_WORD",
      "position": 5
    },
    {
      "token": "共和国",
      "start_offset": 4,
      "end_offset": 7,
      "type": "CN_WORD",
      "position": 6
    },
    {
      "token": "共和",
      "start_offset": 4,
      "end_offset": 6,
      "type": "CN_WORD",
      "position": 7
    },
    {
      "token": "国",
      "start_offset": 6,
      "end_offset": 7,
      "type": "CN_CHAR",
      "position": 8
    },
    {
      "token": "国歌",
      "start_offset": 7,
      "end_offset": 9,
      "type": "CN_WORD",
      "position": 9
    }
  ]
}

智能分词法

代码语言:javascript
复制
GET _analyze
{
  "analyzer":"ik_smart",
  "text":"中华人民共和国国歌"
}

结果

代码语言:javascript
复制
{
  "tokens": [
    {
      "token": "中华人民共和国",
      "start_offset": 0,
      "end_offset": 7,
      "type": "CN_WORD",
      "position": 0
    },
    {
      "token": "国歌",
      "start_offset": 7,
      "end_offset": 9,
      "type": "CN_WORD",
      "position": 1
    }
  ]
}

修改 Mapping中text类型的字段定义

代码语言:javascript
复制
...
"title": {
          "type": "text",
          "analyzer": "ik_max_word",
          "search_analyzer": "ik_max_word",
          "include_in_all": "true"
        },
...

已有大数据需要重建索引

参考 https://github.com/medcl/elasticsearch-analysis-ik

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档