全栈工程师_java全栈工程师_全栈开发者学习经验总结

  • 首页
  • 开发工具
    • 软件安装
    • 软件使用
  • 前端
    • Ionic
    • Android
    • Capacitor
    • Angular
    • Vue
    • 苹果开发者账号
  • 后端
    • Java
    • Python
    • MyBatis
    • Spring
    • SpringBoot
    • SpringMVC
    • SpringCloud
  • 服务器
    • Linux
    • MySQL
    • Nginx
    • Tomcat
    • Docker
  • 其他
    • 生活碎片
    • 报错专区
  • 我
lipsuper
专注产出高质量原创手打文章
  1. 首页
  2. 开发工具
  3. 软件使用
  4. 正文

Elasticsearch基础知识(二)

2020年12月25日 753点热度 0人点赞 0条评论

安装IK分词器

ES自带的分词器是针对英文的,要对中文进行更加智能的分词,推荐使用开源的IK分词器。

安装方法:

1.先到github下载与ES版本相同的压缩包:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.10.1

2.由于之前安装ES的时候把plugins文件夹挂在到了宿主机,所以只需要把这个压缩文件解压上传到plugins文件夹即可。

3.假如我把ik分词器解压到了名为ik的文件夹,那么现在更改它的权限:

chmod -R 777 ik/

4.docker重启es。

# ik分词器测试
POST _analyze
{
  "analyzer": "ik_smart",
  "text": "我今天去朝天门吃了一顿火锅。"
}

 

拓展词库

IK分词器对一些网络流行语,或者自己发明的词语还做不到完美的分词,于是我们可以自己把一些词语添加到拓展词库。

首先准备一个txt文件,里面写你要拓展的词汇,每个词汇占用一行,然后把这个文件放到你自己的网站或者别的能访问到的地方,复制下这个访问地址。

然后前往IK分词器的配置文件目录,编辑IKAnalyzer.cfg.xml文件。

把<entry key="remote_ext_dict">在这里写你的拓展文件地址</entry>这个注释放开。

保存更改过的IKAnalyzer.cfg.xml文件,重启ES。

 

我在txt文件里添加了“尚硅谷”,”巧碧螺“这两个词语

测试:

# ik分词器测试
POST _analyze
{
  "analyzer": "ik_smart",
  "text": "我今天去朝天门吃了一顿火锅尚硅谷巧碧螺。"
}

测试结果:

{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "今天",
      "start_offset" : 1,
      "end_offset" : 3,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "去",
      "start_offset" : 3,
      "end_offset" : 4,
      "type" : "CN_CHAR",
      "position" : 2
    },
    {
      "token" : "朝天门",
      "start_offset" : 4,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "吃了",
      "start_offset" : 7,
      "end_offset" : 9,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "一顿",
      "start_offset" : 9,
      "end_offset" : 11,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "火锅",
      "start_offset" : 11,
      "end_offset" : 13,
      "type" : "CN_WORD",
      "position" : 6
    },
    {
      "token" : "尚硅谷",
      "start_offset" : 13,
      "end_offset" : 16,
      "type" : "CN_WORD",
      "position" : 7
    },
    {
      "token" : "巧碧螺",
      "start_offset" : 16,
      "end_offset" : 19,
      "type" : "CN_WORD",
      "position" : 8
    }
  ]
}

 

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 备忘
最后更新:2020年12月25日

lipsuper

这个人很懒,什么都没留下

点赞
< 上一篇

文章评论

取消回复

COPYRIGHT © 2021 lipsuper.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

渝ICP备2021004735号-1

渝公网安备 50011202502306号