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的更多相关文章

  1. ElasticSearch中文分词器-IK分词器的使用

    IK分词器的使用 首先我们通过Postman发送GET请求查询分词效果 GET http://localhost:9200/_analyze { "text":"农业银行 ...

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

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

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

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

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

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

  5. ElasticSearch搜索引擎安装配置中文分词器IK插件

    近几篇ElasticSearch系列: 1.阿里云服务器Linux系统安装配置ElasticSearch搜索引擎 2.Linux系统中ElasticSearch搜索引擎安装配置Head插件 3.Ela ...

  6. 转:solr6.0配置中文分词器IK Analyzer

    solr6.0中进行中文分词器IK Analyzer的配置和solr低版本中最大不同点在于IK Analyzer中jar包的引用.一般的IK分词jar包都是不能用的,因为IK分词中传统的jar不支持s ...

  7. 我与solr(六)--solr6.0配置中文分词器IK Analyzer

    转自:http://blog.csdn.net/linzhiqiang0316/article/details/51554217,表示感谢. 由于前面没有设置分词器,以至于查询的结果出入比较大,并且无 ...

  8. ElasticSearch安装中文分词器IK

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

  9. ElasticSearch的中文分词器ik

    一.前言   为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了,因此我们需要一个中文分词器来用于搜索和使用. 二.IK ...

随机推荐

  1. 青岛Uber优步司机奖励政策(1月11日~1月17日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. P2351 [SDOi2012]吊灯

    P2351 [SDOi2012]吊灯 https://www.luogu.org/problemnew/show/P2351     题意: 一棵树,能否全部分成大小为x的联通块. 分析: 显然x是n ...

  3. TraceHelper

    public class TraceHelper { private static TraceHelper _traceHelper; private TraceHelper() { } public ...

  4. OSG-HUD

    本文转至http://www.cnblogs.com/shapherd/archive/2010/08/10/osg.html 作者写的比较好,再次收藏,希望更多的人可以看到这个文章 互联网是是一个相 ...

  5. 第六阶段·数据库MySQL及NoSQL实践 第2章·Redis

    01-Redis简介 02-Redis基本安装启动 03-Redis的配置文件基本使用 04-Redis安全管理 05-Redis安全持久化-RDB持久化 06-Redis安全持久化-AOF持久化 0 ...

  6. 打包一个Docker镜像,让你的好友加载开启一个容器,并且每隔一秒输出hello,world到指定的文件中

    一.两个脚本代码 Dockerfile FROM bash COPY . /usr/herui/ WORKDIR /usr/herui/ CMD [ "sh", "hel ...

  7. 数据库Mysql的学习(二)-数据类型和创建

    数据类型:数据列,存储过程参数,表达式和局部变量的数据特征. 整形: tinyint:一个字节,-128到127:2的7次方 smallint:两个字节,-32768到32767:2的15次方 med ...

  8. Python基础 之 tuple类-元组 和 dict类-字典

    tuple 元组 一.tuple 类的基本属性 1.元组,有序:元素不可被修改,不能被增加或者删除tuple类 tu = (111,22,33,44) 一般写元组的时候,推荐在最后加入,和类方法进行区 ...

  9. 【web前端开发】浏览器兼容性处理大全

    1.居中问题 div里的内容,IE默认为居中,而FF默认为左对齐,可以尝试增加代码margin: 0 auto; 2.高度问题 两上下排列或嵌套的div,上面的div设置高度(height),如果di ...

  10. return语句的用法

    1.return语句的作用:a.返回一个值,这个值可以是任意类型.b.使程序返回到操作系统(即终止程序)2.java中对于一个函数,不论有没有返回值类型,都可以带有return 语句.但是区别在于,r ...