下载IK安装包

https://github.com/medcl/elasticsearch-analysis-ik

https://github.com/medcl/elasticsearch-analysis-ik/releases

解压

tar –zxvf elasticsearch-analysis-ik-5.4.0.tar.gz

安装

拷贝elasticsearch-analysis-ik-5.4.0文件夹到

elasticsearch-5.4.0/plugins目录下

重启

重启elasticsearch

测试ik分词器

生成索引

PUT  test

测试细粒度的分词

GET test/_analyze?analyzer=ik_max_word
{
"text":"武汉市长江大桥"
}

返回值

{
"tokens": [
{
"token": "武汉市",
"start_offset": 0,
"end_offset": 3,
"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
},
{
"token": "长江大桥",
"start_offset": 3,
"end_offset": 7,
"type": "CN_WORD",
"position": 3
},
{
"token": "长江",
"start_offset": 3,
"end_offset": 5,
"type": "CN_WORD",
"position": 4
},
{
"token": "大桥",
"start_offset": 5,
"end_offset": 7,
"type": "CN_WORD",
"position": 5
}
]
}

测试粗粒度的分词

GET test/_analyze?analyzer=iksmart
{
"text":"武汉市长江大桥"
}

只返回了两个词

{
"tokens": [
{
"token": "武汉市",
"start_offset": 0,
"end_offset": 3,
"type": "CN_WORD",
"position": 0
},
{
"token": "长江大桥",
"start_offset": 3,
"end_offset": 7,
"type": "CN_WORD",
"position": 1
}
]
}

测试ik分词器官方实例

语法是curl的方式,粘贴到kibana后会自动生成restful方式的查询dsl

  1. create a index
curl -XPUT http://localhost:9200/index
  1. create a mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
} }'

3.index some docs

curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/index/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'

4.query with highlighting

高亮查询,会在返回的匹配关键词前后加上pre_tags、post_tags里的内容

curl -XPOST http://localhost:9200/index/fulltext/_search  -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}
'

返回的结果中命中的关键会加上pretags 和post_tags

{
"took": 14,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2,
"hits": [
{
"_index": "index",
"_type": "fulltext",
"_id": "4",
"_score": 2,
"_source": {
"content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
},
"highlight": {
"content": [
"<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "
]
}
},
{
"_index": "index",
"_type": "fulltext",
"_id": "3",
"_score": 2,
"_source": {
"content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
},
"highlight": {
"content": [
"均每天扣1艘<tag1>中国</tag1>渔船 "
]
}
}
]
}
}

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

  1. elasticsearch安装IK分词插件

    一 打开网页:https://github.com/medcl/elasticsearch-analysis-ik/releases 这个是ik相关的包,找到你想下载的版本,下载对应的zip包 二 然 ...

  2. Elastic Stack 笔记(二)Elasticsearch5.6 安装 IK 分词器和 Head 插件

    博客地址:http://www.moonxy.com 一.前言 Elasticsearch 作为开源搜索引擎服务器,其核心功能在于索引和搜索数据.索引是把文档写入 Elasticsearch 的过程, ...

  3. ES之一:Elasticsearch6.4 windows安装 head插件ik分词插件安装

    准备安装目标:1.Elasticsearch6.42.head插件3.ik分词插件 第一步:安装Elasticsearch6.4 下载方式:1.官网下载 https://www.elastic.co/ ...

  4. Elasticsearch安装中文分词插件ik

    Elasticsearch默认提供的分词器,会把每一个汉字分开,而不是我们想要的依据关键词来分词.比如: curl -XPOST "http://localhost:9200/userinf ...

  5. Linux下,非Docker启动Elasticsearch 6.3.0,安装ik分词器插件,以及使用Kibana测试Elasticsearch,

    Linux下,非Docker启动Elasticsearch 6.3.0 查看java版本,需要1.8版本 java -version yum -y install java 创建用户,因为elasti ...

  6. Windows10安装Elasticsearch IK分词插件

    安装插件 cmd切换到Elasticsearch安装目录下 C:\Users\Administrator>D: D:\>cd D:\Program Files\Elastic\Elasti ...

  7. Centos7部署elasticsearch并且安装ik分词以及插件kibana

    第一步 下载对应的安装包 elasticsearch下载地址:https://www.elastic.co/cn/downloads/elasticsearch ik分词下载:https://gith ...

  8. 如何开发自己的搜索帝国之安装ik分词器

     Elasticsearch默认提供的分词器,会把每个汉字分开,而不是我们想要的根据关键词来分词,我是中国人 不能简单的分成一个个字,我们更希望 “中国人”,“中国”,“我”这样的分词,这样我们就需要 ...

  9. Elasticsearch入门之从零开始安装ik分词器

    起因 需要在ES中使用聚合进行统计分析,但是聚合字段值为中文,ES的默认分词器对于中文支持非常不友好:会把完整的中文词语拆分为一系列独立的汉字进行聚合,显然这并不是我的初衷.我们来看个实例: POST ...

随机推荐

  1. 一次asp.net core3.1打造webapi开发框架的实践

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAigAAAAbCAYAAABWfHSvAAAH30lEQVR4nO1dy5GsMAx80RIESRAEST ...

  2. 鉴于崔庆才大大的对于 beautifulsoup 的再理解

    源地址看 soups = BeautifulSoup(html) soup = BeautifulSoup(open('index.html')) print soup.prettify() Tag通 ...

  3. 【WPF学习】第十七章 键盘输入

    当用户按下键盘上的一个键时,就会发生一系列事件.下表根据他们的发生顺序列出了这些事件: 表 所有元素的键盘事件(按顺序) 键盘处理永远不会像上面看到的这么简单.一些控件可能会挂起这些事件中的某些事件, ...

  4. python+pandas+jupyter notebook 的 hello word

  5. jade 网上看到一个不错的demo 分享 一下 链接

    http://download.csdn.net/detail/sarah1992/9347903 启动的时候 先启动 http://localhost:8080/ 在 node chat 启动 ht ...

  6. 创建自定义路由处理程序(Creating a Custom Route Handler) | 定制路由系统| 高级路由特性 |精通ASP-NET-MVC-5-弗瑞曼

    自定义实现 IRouteHandler

  7. 插入数据值 设置标签属性的值 来自 精通ASP-NET-MVC-5-弗瑞曼

  8. Creating Custom Helper Methods 创建自定义辅助器方法----辅助器方法 ------ 精通ASP.NET MVC 5

    创建内联的辅助器方法 和 拓展方法 好像类似的功能. 不过写在前台更直观

  9. python之pymysql模块

    模块安装 pip install pymysql 执行sql语句 import pymysql #通过pymysql下的connect函数来建立一个传输通道,连接本地mysql的所以host地址是12 ...

  10. ajax--->请求异常 jQuery提示parsererror错误解决办法

    ajax请求异常 jQuery提示parsererror错误解决办法 原因:出现这个错误是因为后端返回的数据类型和前端请求中dataType的要求类型不一致导致的. dataType简介:jquery ...