1.下載安裝(略)
2.IK分詞器
安裝
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.1.1/elasticsearch-analysis-ik-6.1.1.zip
重啟ES 集群
3.對于明確分詞份汗,通過 ik_smart 和 ik_max_word 控制查詢匹配粒度
# 最粗粒度
GET _analyze
{
"analyzer":"ik_smart",
"text":"中華人民共和國"
}
{
? "tokens" : [
? ? {
? ? ? "token" : "中華人民共和國",
? ? ? "start_offset" : 0,
? ? ? "end_offset" : 7,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 0
? ? }
? ]
}
# 最細粒度
GET _analyze
{
"analyzer":"ik_max_word",
"text":"中華人民共和國"
}
{
? "tokens" : [
? ? {
? ? ? "token" : "中華人民共和國",
? ? ? "start_offset" : 0,
? ? ? "end_offset" : 7,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 0
? ? },
? ? {
? ? ? "token" : "中華人民",
? ? ? "start_offset" : 0,
? ? ? "end_offset" : 4,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 1
? ? },
? ? {
? ? ? "token" : "中華",
? ? ? "start_offset" : 0,
? ? ? "end_offset" : 2,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 2
? ? },
? ? {
? ? ? "token" : "華人",
? ? ? "start_offset" : 1,
? ? ? "end_offset" : 3,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 3
? ? },
? ? {
? ? ? "token" : "人民共和國",
? ? ? "start_offset" : 2,
? ? ? "end_offset" : 7,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 4
? ? },
? ? {
? ? ? "token" : "人民",
? ? ? "start_offset" : 2,
? ? ? "end_offset" : 4,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 5
? ? },
? ? {
? ? ? "token" : "共和國",
? ? ? "start_offset" : 4,
? ? ? "end_offset" : 7,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 6
? ? },
? ? {
? ? ? "token" : "共和",
? ? ? "start_offset" : 4,
? ? ? "end_offset" : 6,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 7
? ? },
? ? {
? ? ? "token" : "國",
? ? ? "start_offset" : 6,
? ? ? "end_offset" : 7,
? ? ? "type" : "CN_CHAR",
? ? ? "position" : 8
? ? }
? ]
}
4.自定義詞條
# 未添加新詞條前重付,被斷開
GET _analyze
{
? "analyzer": "ik_smart",
? "text":"洪荒之力"
}
{
? "tokens" : [
? ? {
? ? ? "token" : "洪荒",
? ? ? "start_offset" : 0,
? ? ? "end_offset" : 2,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 0
? ? },
? ? {
? ? ? "token" : "之力",
? ? ? "start_offset" : 2,
? ? ? "end_offset" : 4,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 1
? ? }
? ]
}
# 添加新詞條
cd /opt/softwares/elasticsearch-6.5.4/config/analysis-ik
mkdir custom
vim custom/new_word.dic
-----------------------------
洪荒之力
-----------------------------
vim IKAnalyzer.cfg.xml 通過相對路徑定位宁舰,到擴展詞條路徑
-----------------------------
<entry key="ext_dict">custom/new_word.dic</entry>
-----------------------------
重啟ES,Kibana
新詞項注冊成功
GET _analyze
{
? "analyzer": "ik_smart",
? "text":"洪荒之力"
}
{
? "tokens" : [
? ? {
? ? ? "token" : "洪荒之力",
? ? ? "start_offset" : 0,
? ? ? "end_offset" : 4,
? ? ? "type" : "CN_WORD",
? ? ? "position" : 0
? ? }
? ]
}