Install
1.compile
checkout ik version respective to your elasticsearch version
git checkout tags/{version}
mvn package
copy and unzip target/releases/elasticsearch-analysis-ik-{version}.zip to your-es-root/plugins/ik
2.restart elasticsearch
Tips:
ik_max_word: 會(huì)將文本做最細(xì)粒度的拆分,比如會(huì)將“中華人民共和國國歌”拆分為“中華人民共和國,中華人民,中華,華人,人民共和國,人民,人,民,共和國,共和,和,國國,國歌”,會(huì)窮盡各種可能的組合;
ik_smart: 會(huì)做最粗粒度的拆分,比如會(huì)將“中華人民共和國國歌”拆分為“中華人民共和國,國歌”。
Quick Example
1.create a index
curl -XPUT http://localhost:9200/index
2.create a mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d' { "fulltext": { "_all": { "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "term_vector": "no", "store": "false" }, "properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "include_in_all": "true", "boost": 8 } } } }'
上面這個(gè)rest請求在2.3.4版本的es服務(wù)器上會(huì)執(zhí)行失敗,原因是es 2.3.4上面還沒有text這種類型,"type":"text" 改為 "type":"String"即可
3.index some docs
curl -XPOST http://localhost:9200/index/fulltext/1 -d'{"content":"美國留給伊拉克的是個(gè)爛攤子嗎"}' curl -XPOST http://localhost:9200/index/fulltext/2 -d'{"content":"公安部:各地校車將享最高路權(quán)"}' curl -XPOST http://localhost:9200/index/fulltext/3 -d'{"content":"中韓漁警沖突調(diào)查:韓警平均每天扣1艘中國漁船"}' curl -XPOST http://localhost:9200/index/fulltext/4 -d'{"content":"中國駐洛杉磯領(lǐng)事館遭亞裔男子槍擊 嫌犯已自首"}'
4.query with highlighting
curl -XPOST http://localhost:9200/index/fulltext/_search -d' { "query" : { "match" : { "content" : "中國" }}, "highlight" : { "pre_tags" : ["<tag1>", "<tag2>"], "post_tags" : ["</tag1>", "</tag2>"], "fields" : { "content" : {} } } } '
原文:https://www.cnblogs.com/softidea/p/6081326.html