elasticSearch安裝ik分詞器

ik分詞器github網址:https://github.com/medcl/elasticsearch-analysis-ik

可參考該網頁內容進行安裝

1、獲取分詞的依賴包

    通過git clone https://github.com/medcl/elasticsearch-analysis-ik,下載分詞器源碼

2、進入源碼目錄,將代碼進行打包

打包需要用到jdk,故在安裝ik分詞器之前需要安裝jdk

mvn clean package

以上命令進行打包

在當前目錄下生成了target目錄,打包好的資源都在該目錄下

3、拷貝打包好的資源至ES插件目錄下

cp target/releases/elasticsearch-analysis-ik-{version}.zip your-es-root/plugins/ik

去到your-es-root/plugins/ik目錄,解壓資源包

unzip elasticsearch-analysis-ik-{version}.zip

4、重啓ES

5、測試ik分詞器是否安裝成功

 1、創建一個索引,名爲index。   

curl -XPUT http://localhost:9200/index


    2、爲索引index創建mapping。

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'

{

    "fulltext": {

             "_all": {

            "analyzer": "ik"

        },

        "properties": {

            "content": {

                "type" : "string",

                "boost" : 8.0,

                "term_vector" : "with_positions_offsets",

                "analyzer" : "ik",

                "include_in_all" : true

            }

        }

    }

}'


    3、測試

curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '

{

"text":"世界如此之大"

}'


    顯示結果如下:




{

  "tokens" : [ {

    "token" : "text",

    "start_offset" : 4,

    "end_offset" : 8,

    "type" : "ENGLISH",

    "position" : 1

  }, {

    "token" : "世界",

    "start_offset" : 11,

    "end_offset" : 13,

    "type" : "CN_WORD",

    "position" : 2

  }, {

    "token" : "如此",

    "start_offset" : 13,

    "end_offset" : 15,

    "type" : "CN_WORD",

    "position" : 3

  }, {

    "token" : "之大",

    "start_offset" : 15,

    "end_offset" : 17,

    "type" : "CN_WORD",

    "position" : 4

  } ]

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章