ElasticSerach7.6.0拼音分詞器安裝和使用


第一步:安裝ElasticSearch 7.6.0

由於IK和ElasticSerach已經是編譯好的,不需要編譯,直接在安裝解壓修改配置文件即可

詳情請見另一篇安裝博客:https://www.cnblogs.com/haolb123/p/14051580.html

 

第二步:下載拼音分詞器

由於拼音分詞器並非編譯好的,需要用Maven package 進行打包,maven的下載和使用請百度。

  • 選擇完畢版本,進行選擇Zip包鏈接進行下載 

下載到本地,進行解壓,解壓完畢之后發現是源碼Maven工程,進行mvn packagemaster版本對應Es7.X,默認打包出來是7.7.0,我的es版本是7.6.0

所以要修改C:\Users\Administrator\Downloads\elasticsearch-analysis-pinyin-master\elasticsearch-analysis-pinyin-master\pom.xml的文件。修改后如下:

 

  • 執行打包命令:mvn package

 

  • 打包完成后編譯后的包在target/releases目錄下的elasticsearch-analysis-pinyin-7.6.0.zip

 

  • 將編譯好的zip包進行解壓,進行拷貝,上傳到ElasticSerach plugins的文件夾下

 

  • 重啟ElasticSearchsystemctl restart elasticsearch.service

 

第三步:測試拼音分詞器

  • 創建索引

  1. PUT /medcl/
  2. {
  3.     "settings" : {
  4.         "analysis" : {
  5.             "analyzer" : {
  6.                 "pinyin_analyzer" : {
  7.                     "tokenizer" : "my_pinyin"
  8.                     }
  9.             },
  10.             "tokenizer" : {
  11.                 "my_pinyin" : {
  12.                     "type" : "pinyin",
  13.                     "keep_separate_first_letter" : false,
  14.                     "keep_full_pinyin" : true,
  15.                     "keep_original" : true,
  16.                     "limit_first_letter_length" : 16,
  17.                     "lowercase" : true,
  18.                     "remove_duplicated_term" : true
  19.                 }
  20.             }
  21.         }
  22.     }
  23. }
  • 測試分析器,分析一個中文名字

  1. GET /medcl/_analyze
  2. {
  3.   "text": ["郝利斌"],
  4.   "analyzer": "pinyin_analyzer"
  5. }

返回查詢結果

  • 創建映射

  1. POST /medcl/_mapping
  2. {
  3.   "properties": {
  4.     "name": {
  5.       "type": "keyword",
  6.       "fields": {
  7.         "pinyin": {
  8.           "type": "text",
  9.           "store": false,
  10.           "term_vector": "with_offsets",
  11.           "analyzer": "pinyin_analyzer",
  12.           "boost": 10
  13.         }
  14.       }
  15.     }
  16.   }
  17. }

 

  1. #添加單條數據
  2. POST /medcl/_create/andy
  3. {"name":"劉德華"}
  4.  
  5. #批量添加數據
  6. POST /medcl/_bulk
  7. {"index": {"_index": "medcl","_id": "1"}}
  8. {"name":"儲之源"}
  9. {"index": {"_index": "medcl","_id": "2"}}
  10. {"name":"李根"}
  11. {"index": {"_index": "medcl","_id": "3"}}
  12. {"name":"趙陽"}
  13. {"index": {"_index": "medcl","_id": "4"}}
  14. {"name":"郝利斌"}
  15. {"index": {"_index": "medcl","_id": "5"}}
  16. {"name":"張旭"}
  17. {"index": {"_index": "medcl","_id": "6"}}
  18. {"name":"朱強"}
  19. {"index": {"_index": "medcl","_id": "7"}}
  20. {"name":"黃佳寧"}
  21. {"index": {"_index": "medcl","_id": "8"}}
  22. {"name":"袁曉軍"}

 

  1. #根據條件查詢
  2. GET /medcl/_search
  3. {
  4.   "query": {
  5.     "match": {
  6.       "name.pinyin": "yxj"
  7.     }
  8.   }
  9. }

返回結果:

 

 

 

 

 

 

 

 

 


免責聲明!

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



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