建筑方面的網(wǎng)站起飛頁自助建站平臺
前言
ES中默認(rèn)了許多分詞器,但是對中文的支持并不友好,IK分詞器是一個(gè)專門為中文文本設(shè)計(jì)的分詞工具,它不是ES的內(nèi)置組件,而是一個(gè)需要單獨(dú)安裝和配置的插件。
Ik分詞器的下載安裝(Winows 版本)
下載地址: https://github.com/medcl/elasticsearch-analysis-ik
注意:IK分詞器插件的版本要和ElasticSearch的版本一致
我的ES版本是7.8.0
在 ElasticSearch 所在文件夾中創(chuàng)建ik目錄,并解壓安裝包到ik目錄下
啟動ES,查看日志觀察是否啟動成功
驗(yàn)證測試
可以在kibana中進(jìn)行驗(yàn)證
ik_smart 與 ik_max_word 的異同
首先來看下官方的FAQs
What is the difference between ik_max_word and ik_smart?
ik_max_word: Performs the finest-grained segmentation of the text. For example, it will segment “中華人民共和國國歌” into “中華人民共和國,中華人民,中華,華人,人民共和國,人民,人,民,共和國,共和,和,國國,國歌”, exhaustively generating various possible combinations, suitable for Term Query.
ik_smart: Performs the coarsest-grained segmentation of the text. For example, it will segment “中華人民共和國國歌” into “中華人民共和國,國歌”, suitable for Phrase queries.
Note: ik_smart is not a subset of ik_max_word.
官方這里簡單的描述了一下使用用途,即:
ik_smart 比較適合 match_phrase query,而 ik_max_word 更合適 term query。
ik_smart 的分詞結(jié)果并不是 ik_max_word 的分詞結(jié)果的子集。
到這里ik創(chuàng)建安裝成功!
使用的時(shí)候需要在創(chuàng)建索引mapping的時(shí)候指定字段的分析器(已經(jīng)存在的索引,可以先刪除后創(chuàng)建)