一、IK简介

  IK Analyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包。从2006年12月推出1.0版开始, IKAnalyzer已经推出了4个大版本。最初,它是以开源项目Luence为应用主体的,结合词典分词和文法分析算法的中文分词组件。从3.0版本开 始,IK发展为面向Java的公用分词组件,独立于Lucene项目,同时提供了对Lucene的默认优化实现。在2012版本中,IK实现了简单的分词 歧义排除算法,标志着IK分词器从单纯的词典分词向模拟语义分词衍化。

  IK Analyzer 2012特性:

  1. 采用了特有的“正向迭代最细粒度切分算法“,支持细粒度和智能分词两种切分模式。
  2. 在系统环境:Core2 i7 3.4G双核,4G内存,window 7 64位, Sun JDK 1.6_29 64位 普通pc环境测试,IK2012具有160万字/秒(3000KB/S)的高速处理能力。
  3. 2012版本的智能分词模式支持简单的分词排歧义处理和数量词合并输出。
  4. 采用了多子处理器分析模式,支持:英文字母、数字、中文词汇等分词处理,兼容韩文、日文字符。
  5. 优化的词典存储,更小的内存占用。支持用户词典扩展定义。特别的,在2012版本,词典支持中文,英文,数字混合词语。

二、配置编译环境

  从Github下载的IK分词是源码包,需要maven环境编译

  1、下载maven

# wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

  2、解压 

# tar zxf apache-maven-3.3.-bin.tar.gz -C /usr/src/

  3、配置环境变量

# vi /etc/profile
export MAVEN_HOME=/usr/local/apache-maven-3.3.
export PATH=$PATH:$MAVEN_HOME/bin
# source /etc/profile

三、安装IK分词插件

  1、下载

    到GitHub上下载适合ElasticSearch版本的IK,地址:https://github.com/medcl/elasticsearch-analysis-ik;也可以通过git clone https://github.com/medcl/elasticsearch-analysis-ik,下载分词器源码。

  2、解压编译

# unzip elasticsearch-analysis-ik-master.zip
# cd elasticsearch-analysis-ik-master/
# mvn clean package

  3、复制编译完成的IK分词到elasticsearch的插件路径

# mkdir $elasticsearch/plugins/ik
# cp target/releases/elasticsearch-analysis-ik-1.9..zip $elasticsearch/plugins/ik/
# cd $elasticsearch/plugins/ik/
# unzip elasticsearch-analysis-ik-1.9..zip

  4、重启elasticsearch,使ik插件生效

# /etc/init.d/elasticsearch restart

四、ik分词测试

  1、创建一个索引,名为“index”

# curl -XPUT http://localhost:9200/index

  2、为“index”创建mapping

# curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost":
}
}
}
}'

3、测试

# curl 'http://10.10.10.26:9200/index/_analyze?analyzer=ik&pretty=true' -d '{"text":"中华人民共和国国歌"}'

显示如下:

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

elasticsearch-analysis-ik的Github地址:https://github.com/medcl/elasticsearch-analysis-ik

Elasticsearch安装ik中文分词插件(四)的更多相关文章

  1. elasticsearch 安装ik中文分词

    https://blog.csdn.net/c5113620/article/details/79339541

  2. elasticsearch使用ik中文分词器

    elasticsearch使用ik中文分词器 一.背景 二.安装 ik 分词器 1.从 github 上找到和本次 es 版本匹配上的 分词器 2.使用 es 自带的插件管理 elasticsearc ...

  3. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十九)ES6.2.2 安装Ik中文分词器

    注: elasticsearch 版本6.2.2 1)集群模式,则每个节点都需要安装ik分词,安装插件完毕后需要重启服务,创建mapping前如果有机器未安装分词,则可能该索引可能为RED,需要删除后 ...

  4. Elasticsearch:IK中文分词器

    Elasticsearch内置的分词器对中文不友好,只会一个字一个字的分,无法形成词语,比如: POST /_analyze { "text": "我爱北京天安门&quo ...

  5. es5.0 安装ik中文分词器 mac

    es5.0集成ik中文分词器,网上资料很多,但是讲的有点乱,有的方法甚至不能正常运行此插件 特别注意的而是,es的版本一定要和ik插件的版本相对应: 1,下载ik 插件: https://github ...

  6. 在ElasticSearch中使用 IK 中文分词插件

    我这里集成好了一个自带IK的版本,下载即用, https://github.com/xlb378917466/elasticsearch5.2.include_IK 添加了IK插件意味着你可以使用ik ...

  7. ElasticSearch使用IK中文分词---安装步骤记录

    提示1:必须保证之前的ES中不存在index, 否则ES集群无法启动, 会提示red! 提示2:下载的IK如果太新,会报错 TokenStream被重载Caused by: java.lang.Ver ...

  8. es(elasticsearch)安装IK中文分词器

    IK压缩包下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v6.7.0,需要下载对应的版本 我也上传了 h ...

  9. solr - 安装ik中文分词 和初始化富文本检索

    1.下载安装包 https://repo1.maven.org/maven2/org/apache/solr/solr-dataimporthandler/7.4.0/solr-dataimporth ...

随机推荐

  1. XSLT 调用外部程序

    通常可以通过xslt把一个xml转成html cd.xml <?xml version="1.0" encoding="UTF-8"?> <? ...

  2. socket串口通信

    SocketServer: #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #inclu ...

  3. 【编程范式】C语言1

    最近在网易公开课上看斯坦福大学的<编程范式>,外国人讲课思路就是清晰,上了几节课,感觉难度确实比我们普通大学大很多,但是却很有趣,让人能边学边想. 范式编程,交换两个数,利用 void * ...

  4. 使用protobuf编写配置文件以及读写

    .proto文件示例 message Configure { required ; required uint32 port = ; } 写配置文件 Configure config; config. ...

  5. WEB安全入门

    WEB安全入门 信息安全基础 信息安全目标 真实性:对信息的来源进行判断,能对伪造来源的信息予以鉴别, 就是身份认证. 保密性:保证机密信息不被窃听,盗取,或窃听者不能了解信息的真实含义. 完整性:保 ...

  6. Hibernate配置XML连接数据库

    一.hibernate.cfg.xml 1.配置连接Oracle <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate ...

  7. 实现Avl平衡树

    实现Avl平衡树   一.介绍 AVL树是一种自平衡的二叉搜索树,它由Adelson-Velskii和 Landis于1962年发表在论文<An algorithm for the organi ...

  8. linux下面安装配置mongoDB

    不知道为什么官网最新的2.4我一直解压失败 下载之前确认一下你的操作系统是64位的还是32位的对应去下载 64位链接:http://fastdl.mongodb.org/linux/mongodb-l ...

  9. tastypie Django REST framework

    Its one of the primary authors' lecture on pyCon: http://www.youtube.com/watch?v=Zv26xHYlc8s&nor ...

  10. C++ 容器的综合应用的一个简单实例——文本查询程序

    C++ 容器的综合应用的一个简单实例——文本查询程序 [0. 需求] 最近在粗略学习<C++ Primer 4th>的容器内容,关联容器的章节末尾有个很不错的实例.通过实现一个简单的文本查 ...