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 ...
随机推荐
- vue之文本渲染
Vue使用了基于HTML的模板语法,允许开发者声明式地将DOM绑定至底层Vue实例的数据.所有Vue的模板都是合法的HTML,所以能被遵循规范的浏览器和HTML解析器解析. 在前面,我们一直使用的是{ ...
- appium 点击物理按键
有时候我们遇到一些需要点击手机物理返回按键,或者home键等操作,总结如下: adb shell input keyevent 点击home键: adb shell input keyevent 3 ...
- [转][C#]Combobox 行高
namespace System.Windows.Forms { class ComboBoxEx : ComboBox { public ComboBoxEx() { DrawMode = Syst ...
- []map[][]切片map小计
go中的map我们都知道在进行遍历的时候我们知道他是无序的.对于map[int]interface{}类型的,我们可以通过计算map的长度,通过定长的for循环,进行顺序的输出. 那么如果map的类型 ...
- FTP的应用
创建共享文件,并删除 cd /var/ftp/---------------------(切换到ftp目录下) mkdir aaaaa-------------------(创建aaaaa目录) ll ...
- fragment--的生命周期
官网帮助文档链接: http://developer.Android.com/guide/components/fragments.html 主要看两张图,和跑代码 1,Fragment的生命周: 2 ...
- [UE4]RPC,远程调用
RPC 一.Remote Procedure Call:远程程序调用 二.一个进程调用另外一个进程上的函数 由于“Server-shoot”方法被标记为“在服务器上运行”,所以尽管是在第二个窗口(客户 ...
- Sharing Configuration in ASP.NET Core SPA Scenarios
https://blogs.msdn.microsoft.com/webdev/2017/10/27/sharing-configuration-in-asp-net-core-spa-scenari ...
- VS远程调试与附加调试
使用场景 假如你要开发的程序需要运行在独特的硬件上,比如:服务器,然而这个"独特的硬件"却不能给你装VS,这时候远程调试就登场了. 测试工具/环境一览 Key Value VS版本 ...
- courator - maven
ZK3.4.x: <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-recipes --> <de ...