環境
github下載:https://github.com/medcl/elasticsearch-analysis-ik/releases
注意,IK分詞器插件要與ES版本保持一致;
有的小伙伴在GitHub上下載插件時,沒有發現與ES相對應的版本,可以切換到Tags中選擇分支版本;
例如Branchs串列中僅可能存在主版本號;

切換到右側Tags中查找對應的版本即可;小編這里選擇的7.8.0的版本;

安裝IK
-
解壓縮后拷貝到
ElasticSearch安裝目錄的plugins檔案夾下,默認情況該檔案夾中為空,不存在任何插件,將IK插件存入plugins目錄并重命名ik,如圖:

解壓縮目錄如下:

-
重啟elasticsearch,觀看是否加載插件

-
通過ES自帶的工具查看, 命令列執行
elasticSearch-plugin list

注意,切換到bin目錄下執行上面命令;
kibana實操
介紹兩種分詞用法和區別,主要以努力實作中國夢為例;
ik_smart
ik_smart為最少切分;
如何最少切分呢???
GET _analyze
{
"analyzer": "ik_smart",
"text": "努力實作中國夢"
}
分詞結果:
{
"tokens" : [
{
"token" : "努力實作",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "中國",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "夢",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 2
}
]
}
ik_max_word
ik_max_word為最細粒度劃分;
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
},
{
"token" : "中國",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 3
},
{
"token" : "夢",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 4
}
]
}
自定義分詞格式
比如:超級喜歡溪源博主,用上面兩種分詞,會把溪源,博主分別作為單個詞分開,結果如下:

需求想把溪源,博主作為兩個詞,因此需要我們自定義字典;
- 修改插件組態檔
ik/config/IKAnalyzer.cfg.xml,加入自定義字典;

打開組態檔夾目錄,可以看到已經存在的默認詞庫,如下:

- 自定義
xiyuan.dic檔案
將溪源、博主作為詞存入檔案中;

加入擴展自定義檔案,如下:

- 重啟ES服務和kibana
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
},
{
"token" : "溪源",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "博主",
"start_offset" : 6,
"end_offset" : 8,
"type" : "CN_WORD",
"position" : 3
}
]
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/298079.html
標籤:其他
上一篇:Hadoop集群HDFS、YARN高可用HA詳細配置步驟說明,附Zookeeper搭建詳細步驟【建議收藏!!!】
下一篇:小小MQ,知識點竟然這么多???
