ElasticSearch學習筆記——ik分詞添加詞庫 Elasticsearch學習筆記——分詞

前置條件是安裝ik分詞,請參考

Elasticsearch學習筆記——分詞

1.在ik分詞的config下添加詞庫文件

~/software/apache/elasticsearch-6.2.4/config/analysis-ik$ ls | grep mydic.dic
mydic.dic

內容爲

我給祖國獻石油

2.配置詞庫路徑,編輯IKAnalyzer.cfg.xml配置文件,添加新增的詞庫

3.重啓es

4.測試

data.json

{
        "analyzer":"ik_max_word",
        "text": "我給祖國獻石油"
}

添加之後的ik分詞結果

curl -H 'Content-Type: application/json' http://localhost:9200/_analyze?pretty=true [email protected]
{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "給",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "祖國",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "獻",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "CN_CHAR",
      "position" : 3
    },
    {
      "token" : "石油",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 4
    }
  ]
}

添加之後的ik分詞結果,分詞結果的tokens中增加了 "我給祖國獻石油"

curl -H 'Content-Type: application/json' http://localhost:9200/_analyze?pretty=true [email protected]
{
  "tokens" : [
    {
      "token" : "我給祖國獻石油",
      "start_offset" : 0,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "祖國",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "獻",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "CN_CHAR",
      "position" : 2
    },
    {
      "token" : "石油",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 3
    }
  ]
}

  

 

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