Elasticsearch自定義分詞器
阿新 • • 發佈:2018-12-01
什麼是分詞器
因為Elasticsearch中預設的標準分詞器分詞器對中文分詞不是很友好,會將中文詞語拆分成一個一箇中文的漢字。因此引入中文分詞器-es-ik外掛
演示傳統分詞器
http://192.168.33.129:9200/_analyze
{
"analyzer": "standard",
"text": "奧迪a4l"
}
如下圖所示
請求結果
下載地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
或者下載外掛:https://download.csdn.net/download/qq_38270106/10811833
注意: es-ik分詞外掛版本一定要和es安裝的版本對應
第一步:下載es的IK外掛(資料中有)命名改為ik外掛
第二步: 上傳到/usr/local/elasticsearch-6.4.3/plugins
第三步: 重啟elasticsearch即可
http://192.168.33.129:9200/_analyze
{
"analyzer": "ik_smart",
"text": "奧迪a4l"
}
自定義擴充套件字典
在/usr/local/elasticsearch-6.4.3/plugins/ik/config目錄下
cd /usr/local/elasticsearch-6.4.3/plugins/ik/config
mkdir custom
vi custom/new_word.dic
加入以下內容
老鐵
王者榮耀
洪荒之力
共有產權房
一帶一路
配置分詞器路徑
vi IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 擴充套件配置</comment> <!--使用者可以在這裡配置自己的擴充套件字典 --> <entry key="ext_dict">custom/new_word.dic</entry> <!--使用者可以在這裡配置自己的擴充套件停止詞字典--> <entry key="ext_stopwords"></entry> <!--使用者可以在這裡配置遠端擴充套件字典 --> <!-- <entry key="remote_ext_dict">words_location</entry> --> <!--使用者可以在這裡配置遠端擴充套件停止詞字典--> <!-- <entry key="remote_ext_stopwords">words_location</entry> --> </properties>
重啟elastiasearch
檢視效果