首页 > 其他 > 详细

ES分词

时间:2021-06-05 22:03:11      阅读:23      评论:0      收藏:0      [点我收藏+]

ES默认分词为英文分词(使用空格来进行分词)不符合中文分词要求。例如

GET _analyze
{
"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
    }
  ]
}
View Code

在实际开发中需要安装分词器(IK),安装分词器

解压elasticsearch-analysis-ik-7.6.1

在ES目录里的plugins目录里创建ik文件夹

拷贝elasticsearch-analysis-ik-7.6.1文件里的所有内容到ik文件夹中。如图

技术分享图片

重启ES和kibana

如果ES加载过程中如下

技术分享图片

 

 说明插件配置成功

再在kibana中执行如下解析

GET _analyze
{
"text":"我不喜欢你",
"analyzer": "ik_max_word"
}

输出结果

 

技术分享图片
{
  "tokens" : [
    {
      "token" : "",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "不喜欢",
      "start_offset" : 1,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "喜欢",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "CN_CHAR",
      "position" : 3
    }
  ]
}
View Code

自定义分词

在ik\config文件中创建test.dic文件输入如下内容

技术分享图片

修改IKAnalyzer.cfg.xml配置文件

技术分享图片

 

 重启ES和kibana

执行如下语句

GET _analyze
{
"text":"我不喜欢你",
"analyzer": "ik_max_word"
}

发现分词结果会多出刚才添加的分词内容。如下

技术分享图片

 

ES分词

原文:https://www.cnblogs.com/Duko/p/14853612.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!