elasticsearch-ik
因lucene默认采用英文且英文通过空格就可以断句。而中文则是词组,如果不加载中文词库或插件则会变为一个一个字而非词组,因此需要加载中文词库。
不加分词库所看到的中文分词效果。
post _analyze
{
"text": "中国人民"
}
结果 变为了1个字一个字的:
{
"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
}
]
}
词库下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
https://github.com/medcl/elasticsearch-analysis-ik (readme.txt 阅读安装)
将下载的内容copy到elasticsearch的plugin/ik文件夹下,如果没有则建立此文件夹。重启有效。
ik的作用域
standard
不需要特别定义(默认)
system
在es早期版本可通过在yml中配置 index.analysis.analyzer.default.type: ik
错误 "node settings must not contain any index level settings"
5.x之后elastic不允许在yml文件中添加以index开头的配置文件,要求这些都必须在es启动后通过接口传递
index
首先创建index,然后对index设定属性,最后查看。这里使用的是 sense
目前ik的analysis只能通过挂载在index下,对指定的属性使用。如果新加属性要使用ik,则先到map中进行维护增加属性要使用的analysis。
//创建索引
put /testindex
// 设置analysis 注意_mapping中一个索引对属性创建的map,一旦建立后不能修改,只能新增。
POST /testindex/fulltext/_mapping
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
以上可以看出仅content属性具有ik索词效果,其它属性不具备。
mapping添加 address错误: Mapper for [address] conflicts with existing mapping in other types:\n[mapper [address] has different [analyzer]]
这是因为已经建立了一个属性数据,而这个属性数据在建立时会自动给分配一个mapping映射,因此在建立mapper时说已经存在有一个不同类型的属性。即使删除这笔数也不行,因为属性是只能增加不能修改。
切记切记!!!
ik_max_word 以最大的分词形式进行分词,精细粒度
ik_smart 以最敏捷的分词形式分词,粗粒度
注意:原先老版本的ik已经被ik_max_word,ik_smart取代
// 测试 不要加type不然以为是create数据
post testindex/_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": 3,
"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": 4,
"type": "CN_WORD",
"position": 4
}
]
}
同时可通过建立索引模板来创建索引统一格式。
DELETE _template/temp_ik POST _template/temp_ik
{
"index_patterns": ["ik_*", "*_ik"],
"settings": {
"number_of_shards": 2
},
"mappings": {
"type1": {
"_source": {
"enabled": true
},
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"name":{
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"content":{
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"create_date": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z YYYY"
}
}
}
}
} PUT ik_test POST ik_test/type1/
{
"title": "人民银行",
"name":"7月金融数据传政策暖意",
"content":"社会融资规模增速等数据也传递出这样的信息"
} POST ik_test/type1/_search?pretty=true
{
"query": {"match": {
"title": "人民"
}}
}
elasticsearch-ik的更多相关文章
- jar hell & elasticsearch ik 版本问题
想给es 安装一个ik 的插件, 我的es 是 2.4.0, 下载了一个版本是 1.9.5, [2016-10-09 16:56:26,248][INFO ][node ] [node-2] init ...
- ElasticSearch ik分词安装
1.下载对应版本的ES ik分词 https://github.com/medcl/elasticsearch-analysis-ik/releases 2.解压elasticsearch-analy ...
- 使用 Elasticsearch ik分词实现同义词搜索(转)
1.首先需要安装好Elasticsearch 和elasticsearch-analysis-ik分词器 2.配置ik同义词 Elasticsearch 自带一个名为 synonym 的同义词 fil ...
- Elasticsearch IK+pinyin
如何在Elasticsearch中安装中文分词器(IK+pinyin) 如果直接使用Elasticsearch的朋友在处理中文内容的搜索时,肯定会遇到很尴尬的问题——中文词语被分成了一个一个的汉字 ...
- elasticsearch ik中文分词器安装
特殊说明:灰色文字用来辅助理解的. 安装IK中文分词器 我在百度上搜索了下,大多介绍的都是用maven打包下载下来的源码,这种方法也行,但是不够方便,为什么这么说? 首先需要安装maven吧?其次需要 ...
- 【热更新IK词典】ElasticSearch IK 自动热更新原理与实现
一.热更新原理 elasticsearch开启加载外部词典功功能后,会每60s间隔进行刷新字典.具体原理代码如下所示: public void loadDic(HttpServletRequest r ...
- Windows10安装Elasticsearch IK分词插件
安装插件 cmd切换到Elasticsearch安装目录下 C:\Users\Administrator>D: D:\>cd D:\Program Files\Elastic\Elasti ...
- elasticsearch ik同义词
由于elasticsearch 更新实在太快,配置同义词的资料层次不齐,费尽千辛万苦终于找到了.本文通过一个同义词搜索的简单实例来说明ik同义词的配置. 环境介绍 这点很重要,本文是基于elastic ...
- elasticsearch ik分词
elasticsearch 默认并不支持中文分词,默认将每个中文字切分为一个词,这明显不符合我们的业务要求.这里就需要用到ik分词插件. 本文主要囊括了以下几部分,ik插件安装.ik用法介绍.自定义词 ...
- elasticsearch ik解析器
ik解析器 1. ik解析器 The IK Analysis plugin integrates Lucene IK analyzer (http://code.google.com/p/i ...
随机推荐
- itertools库 combinations() 和 permutations() 组合 和 排列选项的方法
combinations方法重点在组合,permutations方法重在排列. combinations和permutations返回的是对象地址,原因是在python3里面,返回值已经不再是list ...
- 学习笔记之Nearest-Neighbour Searching with PostGIS
PostgreSQL: Documentation: 10: 7.8. WITH Queries (Common Table Expressions) https://www.postgresql.o ...
- redis集群服务启动
1 启动redis服务器 redis-server.exe redis.windows.conf 需要配置config节点的bind ip 2 启动redis集群 开启redis.xx.conf 服务 ...
- 面向对象的轮播js
1.自执行函数的前后要加分号 案例: ;(function(){})(); 2.面向对象的最大优势节省了许多内存 正式开写面向对象的轮播: <!DOCTYPE html> <html ...
- C语言强化——字符串(1)
实现 mystrcpy(), mystrcmp(), mystrcat(), mystrlen() ; #include<stdio.h> void mystrcpy(char *i,ch ...
- [UE4]计算小地图比例尺
一.调整到顶视图,按住鼠标中键从地图的左边拉一根线到右边,可以看到距离是4000厘米(UE4单位是厘米). 二.查看到缩略图片的长度是512px,512/4000 = 0.128,比例尺是0.128. ...
- Zabbix配置参数优化
概述:使用zabbix监控服务器已有一段时间,监控的服务器不到100台,发现刷新zabbix页面有卡顿的现象.而且经常报“Zabbix poller processes more than 75% b ...
- webpack、npm、nginx常用命令
webpack命令:webpack --watch 监听变动并自动打包,简写-wwebpack -p --progress --color 压缩混淆脚本webpack -d 生成映射文件,告知那些模 ...
- sas spawner
注册spawner 服务"c:\Program Files\SASHome\SASFoundation\9.4\cntspawn.exe" -install -service 51 ...
- Visual Ribbon Editor for CRM 连接