当前位置: 首页 > news >正文

5.安装IK分词器

es创建倒排索引的时候,需要对文档进行分词。

搜索时,需要对用户输入的内容分词。但是默认的分词规则对中文处理并不友好。

英语分词器,一个汉子分成一个词,对于java英文单词会分成一个词。

POST /_analyze
{
  "text":"我住在北京这个大城市学习java",
  "analyzer": "english"
}

中文分词器也是一样,一个汉子分成一个词
POST /_analyze
{
  "text":"我住在北京这个大城市学习java",
  "analyzer": "chinese"
}

中文分词器也是一样,一个汉子分成一个词

standard标准分词器也是一样,一个汉子分成一个词

POST /_analyze
{
  "text":"我住在北京这个大城市学习java",
  "analyzer": "standard"
}

都有一个问题,不能对中文很好的分词,按照词语。

处理中文分词,采用ik分词器

有两种:ik_smart 和 ik_max_word

ik_smart 最少切分,分词分的比较少。

ik_max_word 最细切分,分词分的比较多。

下载地址,直接用迅雷下载:

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip

下载后解压文件,文件夹的名字命名为ik即可。(这里命名一定要为ik,否则重启es的docker容器会报错)

然后将ik文件夹上传到centos7服务器,放到docker容器的插件目录即可。

/home/xiankejin/es-plugins/

重启es的docker容器

测试效果:

POST /_analyze
{
  "text":"我住在北京这个大城市学习java",
  "analyzer": "ik_smart"
}

{
  "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" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "这个",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "大城市",
      "start_offset" : 7,
      "end_offset" : 10,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "学习",
      "start_offset" : 10,
      "end_offset" : 12,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "java",
      "start_offset" : 12,
      "end_offset" : 16,
      "type" : "ENGLISH",
      "position" : 6
    }
  ]
}
 

POST /_analyze
{
  "text":"我住在北京这个大城市学习java",
  "analyzer": "ik_max_word"
}

{
  "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" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "这个",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "个大",
      "start_offset" : 6,
      "end_offset" : 8,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "大城市",
      "start_offset" : 7,
      "end_offset" : 10,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "大城",
      "start_offset" : 7,
      "end_offset" : 9,
      "type" : "CN_WORD",
      "position" : 6
    },
    {
      "token" : "城市学",
      "start_offset" : 8,
      "end_offset" : 11,
      "type" : "CN_WORD",
      "position" : 7
    },
    {
      "token" : "城市",
      "start_offset" : 8,
      "end_offset" : 10,
      "type" : "CN_WORD",
      "position" : 8
    },
    {
      "token" : "学习",
      "start_offset" : 10,
      "end_offset" : 12,
      "type" : "CN_WORD",
      "position" : 9
    },
    {
      "token" : "java",
      "start_offset" : 12,
      "end_offset" : 16,
      "type" : "ENGLISH",
      "position" : 10
    }
  ]
}
 

http://www.lryc.cn/news/571181.html

相关文章:

  • ELK在Java的使用
  • Selenium(选择元素,浏览器/元素操作,等待,页面交互)
  • Windows Python 环境管理终极对比:极简方案 VS 传统方案(仅需 2 个软件实现全流程自动化)
  • Selenium(多窗口,frame,验证码,截图,PO模式)
  • rockx读取单张图片并检测图片内人脸的矩形
  • vite的常用配置
  • 「动态规划::数位DP」统计数字递推 / LeetCode 3352|1012(C++)
  • 线程池(Thread Pool)详解
  • 基于Cesium移动的天空云
  • 【Docker基础】Docker核心概念:命名空间(Namespace)之IPC详解
  • 根据Python模块的完整路径import动态导入
  • 05_MinIO+Java SpringBoot 实现透传代理下载
  • 如何确定驱动480x320分辨率的显示屏所需的MCU主频
  • 为何前馈3DGS的边界总是“一碰就碎”?PM-Loss用“3D几何先验”来解
  • Mac 安装JD-GUI
  • 低轨导航 | 低轨卫星导航PNT模型,原理,公式,matlab代码
  • 软件工程:流程图如何画?
  • Python 爬虫入门 Day 5 - 使用 XPath 进行网页解析(lxml + XPath)
  • springboot使用kafka
  • Jmeter的三种参数化方式详解
  • web前端开发核心基础:Html结构分析,head,body,不同标签的作用
  • Java内存模型与线程
  • Anaconda 使用
  • 力扣经典算法篇-17-反转字符串中的单词(逆序遍历,数组分割,正则表达式)
  • 4_STM32F103ZET6芯片系统架构和寄存器
  • 通过自适应训练样本选择弥合基于锚点和无锚点检测之间的差距之ATSS论文阅读
  • 【论文阅读】BACKDOOR FEDERATED LEARNING BY POISONING BACKDOOR-CRITICAL LAYERS
  • Matlab自学笔记五十九:符号变量的代入和替代subs精讲
  • Windows10安装WSL Ubuntu
  • 设计模式:单例模式多种方式的不同实现