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


前置條件是安裝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 -d@data.json
{
  "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 -d@data.json
{
  "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
    }
  ]
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM