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

analysis-ik分词器

analysis-ik分词器

  • 1、安装
    • 离线
    • 在线
  • 2、使用
    • 配置
    • 拓展词典
  • 3、测试
    • ik_smart
    • ik_max_word

1、安装

离线

使用离线安装下载地址https://release.infinilabs.com/analysis-ik/stable/找到对应es版本的ik分词器、下载zip后放到/elasticsearch/plugins/ik文件夹下。重启es即可生效

在线

bin目录下执行脚本/elasticsearch/bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/es版本号(服务器能连通外网)

2、使用

参考官方地址:https://github.com/infinilabs/analysis-ik/blob/master/README.md

配置

ik_smart:最少切分模式。该模式会尽可能少地切分文本
ik_max_word:最细粒度划分模式。该模式会尽可能多地切分文本,将文本中的每个可能的词语都切分

curl -XPOST "http://localhost:9200/test/_mapping" -H 'Content-Type: application/json' -d
'{        "properties": {            "content": {                "type": "text",                "analyzer": "ik_max_word",                "search_analyzer": "ik_smart"            }        }}'

参数说明将索引 testcontent字段类型为text设置为创建时使用ik_max_word创建相关索引、搜索时用ik_smart

拓展词典

elasticsearch/plugins/ik/config/IKAnalyzer.cfg.xml配置文件进行相关修改
在这里插入图片描述
参考链接:
扩展字典
官网

3、测试

注意:已经建好索引

ik_smart

curl -XPOST "http://localhost:9200/_analyze" -H 'Content-Type: application/json' -d'{    "analyzer": "ik_smart",    "text": "中华人民共和国"  }'

分词结果

{"tokens": [{"token": "中华人民共和国","start_offset": 0,"end_offset": 7,"type": "CN_WORD","position": 0}]
}

ik_max_word

curl -XPOST "http://localhost:9200/_analyze" -H 'Content-Type: application/json' -d'{    "analyzer": "ik_max_word",    "text": "中华人民共和国"  }'

分词结果

{"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}]
}
http://www.lryc.cn/news/464563.html

相关文章:

  • 开源的、基于内存的键值存储数据库redis详细介绍
  • 三种容器 std::vector、std::map、std::unordered_set 的对比分析
  • Nuxt3 SSR 服务端渲染部署 PM2 全流程(Nest.js 同理)
  • 如何轻松使用pip安装Git仓库中的私有Python模块(使用pip和Git仓库发布和安装私有Python模块)
  • 写 R 包教程
  • 【java】数组(超详细总结)
  • @KafkaListener注解
  • 2025年计算机视觉研究进展与应用国际学术会议 (ACVRA 2025)
  • 第二代GPT-SoVITS V2:让声音克隆变得简单
  • 基于x86_64汇编语言简单教程6: 变量,常量,与运算
  • Vue-router 路由守卫执行流程图
  • ES6 中函数参数的默认值
  • Redis知识应用索引指南
  • ES6扩展运算符
  • 【树莓派 5B】Python 版本切换
  • windows C++-有效使用PPL(五)
  • 【排序】——1.冒泡排序法(含优化)
  • 在MySQL中创建数据库和表
  • Hadoop 安装教程——单节点模式和分布式模式配置
  • 给c++小白的教程10:一维数组
  • 【排序】3.希尔排序法
  • 商品详情数据API接口概述(json数据格式返回参考)
  • Jmeter简介
  • 网页前端开发之HTML入门篇:标题标签 heading
  • 医院信息化与智能化系统(3)
  • 数据结构(线性表)
  • ArcGIS Pro SDK (十八)栅格
  • c++ 对象作用域
  • 【无标题】海尔AI英语面试
  • 软件设计模式------概述