ElasticSearch6 IK 同義詞 配置

網(wǎng)上大多數(shù)都是 es5 的配置方法, 關(guān)于 es6 的同義詞配置 斷斷續(xù)續(xù)研究了好幾天,今天本地 服務(wù)器上,終于配成功了,記錄一下!

1. 創(chuàng)建一個(gè)索引
curl -v -X PUT localhost:9200/station_index
2. close index,因?yàn)槲覀兘酉聛硪獙υ撍饕O(shè)置
curl -XPOST 'localhost:9200/station_index/_close'
3. 配置ik同義詞
curl -l -H "Content-Type:application/json" -H "Accept:application/json" -X PUT 'http://localhost:9200/station_index/_settings?preserve_existing=true' -d '{
  "index.analysis.analyzer.ik_syno.filter" : [
    "my_synonym_filter"
  ],
  "index.analysis.analyzer.ik_syno.tokenizer" : "ik_max_word",
  "index.analysis.analyzer.ik_syno.type" : "custom",
  "index.analysis.analyzer.ik_syno_smart.filter" : [
    "my_synonym_filter"
  ],
  "index.analysis.analyzer.ik_syno_smart.tokenizer" : "ik_smart",
  "index.analysis.analyzer.ik_syno_smart.type" : "custom",
  "index.analysis.filter.my_synonym_filter.synonyms_path" : "synonyms.txt",
  "index.analysis.filter.my_synonym_filter.type" : "synonym"
}'

如 synonyms.txt 發(fā)生變動,重啟 es 服務(wù)器即可生效

我遇到的問題:
問題1:這里說一下,網(wǎng)上很多博客 修改 elasticsearch.yml 的做法,在 es6 中無法使用,例如:


es 服務(wù)器 告訴我 ,自從5.x 以后他們就不讓這么做啦,只能通過訪問 API 來設(shè)置,好吧,我直接復(fù)制改一下索引搞定

問題2:"type":"malformed_input_exception","reason":"Input length = 1"
詳細(xì)信息如下

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"failed to build synonyms"}],
"type":"illegal_argument_exception","reason":"failed to build synonyms",
"caused_by":{"type":"malformed_input_exception","reason":"Input length = 1"}},"status":400}

原因:這個(gè)問題是由于 synonyms.txt 解析錯誤造成
1)檢查你的語法配置是否如下

程王, 程王線 => 程王

2)編碼 UTF-8 (很關(guān)鍵!??!我就是被坑在這里)


4. open index
curl -XPOST 'localhost:9200/station_index/_open'
5. 測試
curl -l -H "Content-Type:application/json" -H "Accept:application/json" -X POST 'http://localhost:9200/station_index/_analyze' -d '{
  "analyzer" : "ik_syno_smart",
  "text" : "程王線"
}'

到這里已經(jīng)大功告成了!

下面再把我的映射貼出來,有需要的可以參考

curl -l -H "Content-Type:application/json" -H "Accept:application/json" -X POST 'localhost:9200/station_index/station/_mapping' -d '{
    "properties": {
        "name": {
            "type": "text",
            "analyzer": "ik_syno_smart",
            "search_analyzer": "ik_syno_smart"
        }
    }
}'
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容