Elasticsearch 中文分词器IK
1、安装说明
https://github.com/medcl/elasticsearch-analysis-ik
2、release版本
https://github.com/medcl/elasticsearch-analysis-ik/releases
3、安装插件
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.1/elasticsearch-analysis-ik-6.1.1.zip
[es@bigdata-senior01 elasticsearch-6.5.1]$ ll plugins/analysis-ik/
总用量 1428
-rw-r--r-- 1 es es 263965 12月 12 10:30 commons-codec-1.9.jar
-rw-r--r-- 1 es es 61829 12月 12 10:30 commons-logging-1.2.jar
-rw-r--r-- 1 es es 54693 12月 12 10:30 elasticsearch-analysis-ik-6.5.1.jar
-rw-r--r-- 1 es es 736658 12月 12 10:30 httpclient-4.5.2.jar
-rw-r--r-- 1 es es 326724 12月 12 10:30 httpcore-4.4.4.jar
-rw-r--r-- 1 es es 1805 12月 12 10:30 plugin-descriptor.proper
也可以自己下载包之后解压缩,copy到plugins下即可
4、扩展词库
在es目录下config/analysis-ik/中
新建自己的词库,utf8编码
mkdir mydic
vi myword001.dic
魔兽世界
李云龙
嫦娥
修改配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">mydic/myword001.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
官网说明:
IKAnalyzer.cfg.xml can be located at {conf}/analysis-ik/config/IKAnalyzer.cfg.xml or {plugins}/elasticsearch-analysis-ik-*/config/IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">custom/ext_stopword.dic</entry>
<!--用户可以在这里配置远程扩展字典 -->
<entry key="remote_ext_dict">location</entry>
<!--用户可以在这里配置远程扩展停止词字典-->
<entry key="remote_ext_stopwords">http://xxx.com/xxx.dic</entry>
</properties>
测试:
GET _analyze
{
"analyzer": "ik_smart",
"text": "魔兽世界"
} {
"tokens" : [
{
"token" : "魔兽世界",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
}
]
}
GET _analyze
{
"analyzer": "ik_max_word",
"text": "魔兽世界"
} {
"tokens" : [
{
"token" : "魔兽世界",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "魔兽",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "世界",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 2
}
]
}
ik_smart 是粗粒度分词,分过的词不在参与分词。
ik_max_word是细粒度分词,根据可能的词进行组合. 5、使用分词
5.1直接在settings里设置缺省的分词器
PUT user
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1,
"index" : {
"analysis.analyzer.default.type": "ik_smart"
}
}
}
} PUT bus3
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"index" : {
"analysis.analyzer.default.type": "ik_max_word",
"analysis.search_analyzer.default.type":"ik_smart"
}
}
}
} GET /bus/_settings
返回:
{
"bus3" : {
"settings" : {
"index" : {
"number_of_shards" : "1",
"provided_name" : "bus3",
"creation_date" : "1545318988048",
"analysis" : {
"analyzer" : {
"default" : {
"type" : "ik_max_word"
}
},
"search_analyzer" : {
"default" : {
"type" : "ik_smart"
}
}
},
"number_of_replicas" : "0",
"uuid" : "dOU8yi5pRdi-0Akq_zCWtw",
"version" : {
"created" : "6050199"
}
}
}
}
}
5.2 在mapping里对每个字段设置
PUT bus
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"product":{
"properties": {
"name":{
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
} }
}
GET bus/_mapping
{
"bus" : {
"mappings" : {
"product" : {
"properties" : {
"name" : {
"type" : "text",
"analyzer" : "ik_max_word"
}
}
}
}
}
}
查询测试1:查询使用分词器ik_smart
GET /bus/_search
{
"query": {
"match": {
"name": {
"query": "公交车"
, "analyzer": "ik_smart"
}
}
},
"highlight": {
"fields": {"name": {}}
}
} 返回:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 1.8566245,
"hits" : [
{
"_index" : "bus",
"_type" : "product",
"_id" : "1",
"_score" : 1.8566245,
"_source" : {
"name" : "公交车1路",
"desc" : "从东站到西站",
"price" : 10,
"producer" : "东部公交",
"tags" : [
"普通",
"单层"
],
"memo" : "a test"
},
"highlight" : {
"name" : [
"<em>公交车</em>1路"
]
}
}
]
}
}
查询测试2:查询使用分词器ik_max_word
GET /bus/_search
{
"from": 0, "size": 1,
"query": {
"match": {
"name": {
"query": "公交车"
, "analyzer": "ik_max_word"
}
}
},
"highlight": {
"fields": {"name": {}}
}
}
返回:
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 7.426498,
"hits" : [
{
"_index" : "bus",
"_type" : "product",
"_id" : "1",
"_score" : 7.426498,
"_source" : {
"name" : "公交车1路",
"desc" : "从东站到西站",
"price" : 10,
"producer" : "东部公交",
"tags" : [
"普通",
"单层"
],
"memo" : "a test"
},
"highlight" : {
"name" : [
"<em>公交</em><em>车</em>1路"
]
}
}
]
}
}
可以看到高亮部分是不一样的,一般情况我们可以分词用ik_max_word,查询分词用ik_smart。
Elasticsearch 中文分词器IK的更多相关文章
- ElasticSearch中文分词器-IK分词器的使用
IK分词器的使用 首先我们通过Postman发送GET请求查询分词效果 GET http://localhost:9200/_analyze { "text":"农业银行 ...
- 如何在Elasticsearch中安装中文分词器(IK)和拼音分词器?
声明:我使用的Elasticsearch的版本是5.4.0,安装分词器前请先安装maven 一:安装maven https://github.com/apache/maven 说明: 安装maven需 ...
- 如何给Elasticsearch安装中文分词器IK
安装Elasticsearch安装中文分词器IK的步骤: 1. 停止elasticsearch 2.2的服务 2. 在以下地址下载对应的elasticsearch-analysis-ik插件安装包(版 ...
- 沉淀再出发:ElasticSearch的中文分词器ik
沉淀再出发:ElasticSearch的中文分词器ik 一.前言 为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了 ...
- ElasticSearch搜索引擎安装配置中文分词器IK插件
近几篇ElasticSearch系列: 1.阿里云服务器Linux系统安装配置ElasticSearch搜索引擎 2.Linux系统中ElasticSearch搜索引擎安装配置Head插件 3.Ela ...
- 转:solr6.0配置中文分词器IK Analyzer
solr6.0中进行中文分词器IK Analyzer的配置和solr低版本中最大不同点在于IK Analyzer中jar包的引用.一般的IK分词jar包都是不能用的,因为IK分词中传统的jar不支持s ...
- 我与solr(六)--solr6.0配置中文分词器IK Analyzer
转自:http://blog.csdn.net/linzhiqiang0316/article/details/51554217,表示感谢. 由于前面没有设置分词器,以至于查询的结果出入比较大,并且无 ...
- ElasticSearch安装中文分词器IK
1.安装IK分词器,下载对应版本的插件,elasticsearch-analysis-ik中文分词器的开发者一直进行维护的,对应着elasticsearch的版本,所以选择好自己的版本即可.IKAna ...
- ElasticSearch的中文分词器ik
一.前言 为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了,因此我们需要一个中文分词器来用于搜索和使用. 二.IK ...
随机推荐
- 上海Uber优步司机奖励政策(12月20日到12月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- LeetCode:36. Valid Sudoku(Medium)
1. 原题链接 https://leetcode.com/problems/valid-sudoku/description/ 2. 题目要求 给定一个 9✖️9 的数独,判断该数独是否合法 数独用字 ...
- EF Core ThenInclude 2.0自动完成提示有误,坑了一下
只要代码正确,可以编译运行的... https://github.com/dotnet/roslyn/issues/8237
- 限时购校验小工具&dubbo异步调用实现限
本文来自网易云社区 作者:张伟 背景 限时购是网易考拉目前比较常用的促销形式,但是前期创建一个限时购活动时需要各个BU按照指定的Excel格式进行选品提报,为了保证提报数据准确,运营需要人肉校验很多信 ...
- Java连接redis集群操作存储、删除以及获取值
pom文件添加: <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> &l ...
- hdu2094产生冠军(思维题)
产生冠军 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Qt 5 最新信号和槽连接方式以及Lambda表达式
最近学习Qt,发现新大陆,这里做下记录. 主要内容就是原始Qt4的信号槽连接方式,以及Qt5新版的连接方式,还有件事简单演示一下lambda表达式的使用方式 代码如下 /* * 作者:张建伟 * 时间 ...
- Linux命令应用大词典-第35章 终端
35.1 tty:显示当前连接到当前标准输入的终端设备文件名 35.2 consoletype:显示连接到标准输入的控制台类型 35.3 fgconsole:显示活动的虚拟终端数量 35.4 ming ...
- CSS3自定义字体
原文摘自:https://www.cnblogs.com/moqiutao/archive/2015/12/23/5070463.html 总节: 1) 定义字体标准格式: @font-face { ...
- leetcode-岛屿的个数
岛屿的个数 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 ...