@羲凡——只为了更好的活着
Elasticsearch 安装ik和pinyin分词器——elasticsearch6.5.4
默认你已经安装好elasticsearch6.5.4,如果没有请先参照我另一篇博客 https://blog.csdn.net/weixin_42003671/article/details/89487433 。本文也是用 deptest30、deptest33、deptest34 三台机器做测试
一、安装ik和pinyin分词器
安装IK分词器github上有说明,
地址如下:https://github.com/medcl/elasticsearch-analysis-ik/tree/6.x#install
1.下载安装包
在以下两个网站中找到与自己es对应的ik和pinyin版本
https://github.com/medcl/elasticsearch-analysis-ik/releases
https://github.com/medcl/elasticsearch-analysis-pinyin/releases
我使用的是 elasticsearch6.5.4 ,所以本文的下载地址如下
ik下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip
pinyin下载地址:https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.5.4/elasticsearch-analysis-pinyin-6.5.4.zip
2.将安装包解压到${ES_HOME}/plugins/ik目录下
现在一台机器上安装,比如 deptest30
创建 ${ES_HOME}/plugins/ik 和 ${ES_HOME}/plugins/pinyin 目录,并解压到该目录下
mkdir -p ${ES_HOME}/plugins/ik
mkdir -p ${ES_HOME}/plugins/pinyin
unzip elasticsearch-analysis-ik-6.5.4.zip -d ${ES_HOME}/plugins/ik
unzip elasticsearch-analysis-pinyin-6.5.4.zip -d ${ES_HOME}/plugins/pinyin
3.分发到集群的其他机器上,并重启es
scp -r ${ES_HOME}/plugins/ik hadoop@deptest33:${ES_HOME}/plugins/
scp -r ${ES_HOME}/plugins/ik hadoop@deptest34:${ES_HOME}/plugins/
scp -r ${ES_HOME}/plugins/pinyin hadoop@deptest33:${ES_HOME}/plugins/
scp -r ${ES_HOME}/plugins/pinyin hadoop@deptest34:${ES_HOME}/plugins/
然后重启即可
切记一定要重启es哦
切记一定要重启es哦
切记一定要重启es哦
二、测试ik/pinyin分词器
测试ik分词器github上有案例,
地址如下:https://github.com/medcl/elasticsearch-analysis-ik/tree/6.x#quick-example
测试pinyin分词器github上有案例,
地址如下:https://github.com/medcl/elasticsearch-analysis-pinyin
以下是官网上测试ik分词器的案例
1.创建一个索引
curl -XPUT http://deptest30:9200/index?pretty
2.创建一个mapping
curl -XPOST http://deptest30:9200/index/fulltext/_mapping?pretty -H 'Content-Type:application/json' -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
3.向索引中添加文档
curl -XPOST 'deptest30:9200/index/fulltext/_bulk?pretty' -H 'Content-Type:application/json' -d'
{"index":{"_id":"1"}}
{"content":"美国留给伊拉克的是个烂摊子吗"}
{"index":{"_id":"2"}}
{"content":"公安部:各地校车将享最高路权"}
{"index":{"_id":"3"}}
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
{"index":{"_id":"4"}}
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
4.查询并highlight显示
curl -XPOST http://deptest30:9200/index/fulltext/_search?pretty -H 'Content-Type:application/json' -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}'
====================================================================
@羲凡——只为了更好的活着
若对博客中有任何问题,欢迎留言交流