es-ikES上使用IK中文分詞器
IK中文分詞器在Elasticsearch上的使用。原生IK中文分詞是從文件系統(tǒng)中讀取詞典,es-ik本身可擴(kuò)展成從不同的源讀取詞典。目前提供從sqlite3數(shù)據(jù)庫中讀取。es-ik-plugin-sqlite3使用方法:
1. 在elasticsearch.yml中設(shè)置你的sqlite3詞典的位置:
ik_analysis_db_path: /opt/ik/dictionary.db
我提供了默認(rèn)的詞典:https://github.com/zacker330/es-ik-sqlite3-dictionary
2. 安裝(目前是1.0.1版本)
./bin/plugin -i ik-analysis -u https://github.com/zacker330/es-ik-plugin-sqlite3-release/raw/master/es-ik-sqlite3-1.0.1.zip
3. 現(xiàn)在可以測(cè)試了:
1. 創(chuàng)建index
curl -X PUT -H "Cache-Control: no-cache" -d '{
"settings":{
"index":{
"number_of_shards":1,
"number_of_replicas": 1
}
}
}' 'http://localhost:9200/songs/'
2. 創(chuàng)建map:
curl -X PUT -H "Cache-Control: no-cache" -d '{
"song": {
"_source": {"enabled": true},
"_all": {
"indexAnalyzer": "ik_analysis",
"searchAnalyzer": "ik_analysis",
"term_vector": "no",
"store": "true"
},
"properties":{
"title":{
"type": "string",
"store": "yes",
"indexAnalyzer": "ik_analysis",
"searchAnalyzer": "ik_analysis",
"include_in_all": "true"
}
}
}
}
' 'http://localhost:9200/songs/_mapping/song'
3.
curl -X POST -d '林夕為我們作詞' 'http://localhost:9200/songs/_analyze?analyzer=ik_analysis'
response:
{"tokens":[{"token":"林夕","start_offset":0,"end_offset":2,"type":"CN_WORD","position":1},{"token":"作詞","start_offset":5,"end_offset":7,"type":"CN_WORD","position":2}]}
評(píng)論
圖片
表情
