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月21日到12月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- android 8.0 Account行为变更 账号系统
我们有个方法,是判断系统的账号有没有登录. public static boolean isAccountLogin(Context context) { String df = "com. ...
- Python-内置函数3
'''1.lambda 声明一个匿名函数,并且自动给你返回值2.map()3.float()4.globals()5.locals()6.input()7.print()8.int()9.int()1 ...
- Manual install on Windows 7 with Apache and MySQL
These are instructions for installing on Windows 7 desktop (they may also be useful for a server ins ...
- 刚安装的Linux Centos7使用yum安装firefox时提示:cannot find a valid baseurl for repo
出现这个问题是因为yum在安装包的过程中,虽然已经联网,但是没法解析远程包管理库对应的域名,所以我们只需要在网络配置中添加上DNS对应的ip地址即可. 解决参考链接:https://blog.csdn ...
- Fiddler - 拦截手机请求
1. 在电脑上安装Fillder. 安装好之后的Fiddler 打开是这样的: 2. 浏览器访问http://127.0.0.1:8888/fiddler,下载证书并安装 3. 打开抓取https请求 ...
- 阿里云ECS下CentOS7.4 yum安装Python3.6环境
一.安装EPEL和IUS软件源 二.安装Python3.6 三.创建python3软链接连接符 四.安装pip3 五.创建pip3链接符 六.进行验证是否安装成功 一.安装EPEL和IUS软件源 yu ...
- 从零开始的Python学习Episode 5——字典
字典 字典是另一种可变容器模型,且可存储任意类型对象. 一.添加 (1)直接添加 dict={'name':'smilepup'} dict['age']=20 dict['name']='piggy ...
- Exact Inference in Graphical Models
独立(Independence) 统计独立(Statistical Independence) 两个随机变量X,Y统计独立的条件是当且仅当其联合概率分布等于边际概率分布之积: \[ X \perp Y ...
- 150命令之线上查询及帮助命令 man hellp
150命令之线上查询及帮助命令 man 查询命令的帮助 man + 命令 NAME ls - list directory contents 命令+命令简单说明 SYNOPSIS ...