Elasticsearch默认提供的分词器,会把每一个汉字分开,而不是我们想要的依据关键词来分词。比如:

curl -XPOST  "http://localhost:9200/userinfo/_analyze?analyzer=standard&pretty=true&text=我是中国人"

我们会得到这种结果:

{
tokens: [
{
token: text
start_offset: 2
end_offset: 6
type: <ALPHANUM>
position: 1
}
{
token: 我
start_offset: 9
end_offset: 10
type: <IDEOGRAPHIC>
position: 2
}
{
token: 是
start_offset: 10
end_offset: 11
type: <IDEOGRAPHIC>
position: 3
}
{
token: 中
start_offset: 11
end_offset: 12
type: <IDEOGRAPHIC>
position: 4
}
{
token: 国
start_offset: 12
end_offset: 13
type: <IDEOGRAPHIC>
position: 5
}
{
token: 人
start_offset: 13
end_offset: 14
type: <IDEOGRAPHIC>
position: 6
}
]
}

正常情况下。这不是我们想要的结果,比方我们更希望 “中国人”,“中国”,“我”这种分词。这样我们就须要安装中文分词插件,ik就是实现这个功能的。

elasticsearch-analysis-ik
是一款中文的分词插件,支持自己定义词库。

安装步骤:

1、到github站点下载源码。站点地址为:https://github.com/medcl/elasticsearch-analysis-ik

右側下方有一个button“Download ZIP"。点击下载源码elasticsearch-analysis-ik-master.zip。

2、解压文件elasticsearch-analysis-ik-master.zip,进入下载文件夹,运行命令:

unzip elasticsearch-analysis-ik-master.zip

3、将解压文件夹文件里config/ik文件夹拷贝到ES安装文件夹config文件夹下。

4、由于是源码。此处须要使用maven打包,进入解压文件夹中,运行命令:

mvn clean package

5、将打包得到的jar文件elasticsearch-analysis-ik-1.2.8-sources.jar拷贝到ES安装文件夹的lib文件夹下。

6、在ES的配置文件config/elasticsearch.yml中添加ik的配置。在最后添加:

index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true

index.analysis.analyzer.ik.type : “ik”

7、又一次启动elasticsearch服务,这样就完毕配置了,收入命令:

curl -XPOST  "http://localhost:9200/userinfo/_analyze?analyzer=ik&pretty=true&text=我是中国人"

測试结果例如以下:

{
tokens: [
{
token: text
start_offset: 2
end_offset: 6
type: ENGLISH
position: 1
}
{
token: 我
start_offset: 9
end_offset: 10
type: CN_CHAR
position: 2
}
{
token: 中国人
start_offset: 11
end_offset: 14
type: CN_WORD
position: 3
}
{
token: 中国
start_offset: 11
end_offset: 13
type: CN_WORD
position: 4
}
{
token: 国人
start_offset: 12
end_offset: 14
type: CN_WORD
position: 5
}
]
}

说明:

1、ES安装插件本来使用使用命令plugin来完毕。可是我本机安装ik时一直不成功,所以就使用源码打包安装了。

2、自己定义词库的方式,请參考 https://github.com/medcl/elasticsearch-analysis-ik

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

  1. 如何给Elasticsearch安装中文分词器IK

    安装Elasticsearch安装中文分词器IK的步骤: 1. 停止elasticsearch 2.2的服务 2. 在以下地址下载对应的elasticsearch-analysis-ik插件安装包(版 ...

  2. ElasticSearch安装中文分词器IK

    1.安装IK分词器,下载对应版本的插件,elasticsearch-analysis-ik中文分词器的开发者一直进行维护的,对应着elasticsearch的版本,所以选择好自己的版本即可.IKAna ...

  3. Elasticsearch如何安装中文分词插件ik

    elasticsearch-analysis-ik 是一款中文的分词插件,支持自定义词库. 安装步骤: 1.到github网站下载源代码,网站地址为:https://github.com/medcl/ ...

  4. ElasticSearch-5.0.0安装中文分词插件IK

    Install IK 源码地址:https://github.com/medcl/elasticsearch-analysis-ik,git clone下来. 1.compile mvn packag ...

  5. elasticsearch安装中文分词器插件smartcn

    原文:http://blog.java1234.com/blog/articles/373.html elasticsearch安装中文分词器插件smartcn elasticsearch默认分词器比 ...

  6. 如何在Elasticsearch中安装中文分词器(IK)和拼音分词器?

    声明:我使用的Elasticsearch的版本是5.4.0,安装分词器前请先安装maven 一:安装maven https://github.com/apache/maven 说明: 安装maven需 ...

  7. 沉淀再出发:ElasticSearch的中文分词器ik

    沉淀再出发:ElasticSearch的中文分词器ik 一.前言   为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了 ...

  8. ElasticSearch 安装中文分词器

    1.安装中文分词器IK 下载地址:https://github.com/medcl/elasticsearch-analysis-ik 在线下载安装: elasticsearch-plugin.bat ...

  9. ElasticSearch安装中文分词器IKAnalyzer

    # ElasticSearch安装中文分词器IKAnalyzer  本篇主要讲解如何在ElasticSearch中安装中文分词器IKAnalyzer,拆分的每个词都是我们熟知的词语,从而建立词汇与文档 ...

随机推荐

  1. Lazarus 字符集转换 Utf8ToAnsi,UTF8ToWinCP,UTF8ToSys,UTF8ToConsole

    由于Lazarus从1.2版开始默认字符集就是UTF8,如果要转到系统正常显示或文本保存,就必须对字符集进行转换.Lazarus提供了很多函数.如题. 那么这里面有什么关系呢? UTF8ToSys 需 ...

  2. Erwin 带注释(comment )

    1. Database>Pre & Post Script > Model-level %ForEachTable() { alter TABLE %TableName COMME ...

  3. HDU_1176_免费馅饼_16.4.23再做

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. HDU_1874_畅通工程续_最短路问题

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. View Programming Guide for iOS

    https://developer.apple.com/library/archive/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Wi ...

  6. [转载] Linux Futex的设计与实现

    Linux Futex的设计与实现 引子 在编译2.6内核的时候,你会在编译选项中看到[*] Enable futex support这一项,上网查,有的资料会告诉你"不选这个内核不一定能正 ...

  7. 51nod 1083 矩阵取数问题【动态规划】

    一个N*N矩阵中有不同的正整数,经过这个格子,就能获得相应价值的奖励,从左上走到右下,只能向下向右走,求能够获得的最大价值. 例如:3 * 3的方格. 1 3 3 2 1 3 2 2 1 能够获得的最 ...

  8. 最短网络 Agri-Net

    题目背景 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 题目描述 约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享给其 ...

  9. T1462 素数和 codevs

    题目描述 Description 给定2个整数a,b 求出它们之间(不含a,b)所有质数的和. 输入描述 Input Description 一行,a b(0<=a,b<=65536) 输 ...

  10. 一篮子苹果,每天吃一半多一个吃,第十天吃一半多一个后就剩余一个,求一共多少个苹果,JAVA版

    /** * @author xuzhu **/public class TestApple { public static void main(String[] args) { int days = ...