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. web项目优化

    1 循环时没有使用break  案例:查找一个值是否在数组中存在(为举例舍弃自带函数) $aa=123; $arr=array(234,123,5,6,45646,346,23); foreach($ ...

  2. Spring Cloud(九):配置中心(消息总线)【Finchley 版】

    Spring Cloud(九):配置中心(消息总线)[Finchley 版]  发表于 2018-04-19 |  更新于 2018-05-07 |  我们在 Spring Cloud(七):配置中心 ...

  3. spark-shell解析

    spark-shell 作用: 调用spark-submit脚本,如下参数 --classorg.apache.spark.repl.Main --name "Spark shell&quo ...

  4. 干货来袭:Redis5.0支持的新功能说明

    Redis5.0支持的新特性说明 本文内容来自华为云帮助中心 华为云DCS的Redis5.x版本继承了4.x版本的所有功能增强以及新的命令,同时还兼容开源Redis5.x版本的新增特性. Stream ...

  5. 机器学习实战笔记一:K-近邻算法在约会网站上的应用

    K-近邻算法概述 简单的说,K-近邻算法采用不同特征值之间的距离方法进行分类 K-近邻算法 优点:精度高.对异常值不敏感.无数据输入假定. 缺点:计算复杂度高.空间复杂度高. 适用范围:数值型和标称型 ...

  6. redis 编译安装错误问题

    编译redis安装的时候报错如下: make[1]: [persist-settings] Error 2 (ignored) CC adlist.o/bin/sh: cc: command not ...

  7. Thunder团队第六周 - Scrum会7

    Scrum会议7 小组名称:Thunder 项目名称:i阅app Scrum Master:杨梓瑞 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...

  8. Thunder团队第六周 - Scrum会议2

    Scrum会议2 小组名称:Thunder 项目名称:i阅app Scrum Master:宋雨 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ...

  9. Thunder团队贡献分分配规则

    规则1:基础分,拿出总分的40%进行均分. 规则2:参与会议者,每人次加0.5分. 规则3:积极贡献者,通过团队投票,半数及以上同意,每次加0.5分. 规则4:根据项目完成情况,核实每个人的工作量,投 ...

  10. 软件功能-东北师大站-第三次作业(PSP)

    1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 本周PSP饼状图