1. 下载elasticsearch-analysis-pinyin插件:

由于github网站过慢,使用gitcode中代码进行编译:
https://gitcode.net/mirrors/medcl/elasticsearch-analysis-pinyin
选择对应的版本,我的elasticsearch是7.x版本所以下载master分支代码:
image.png

2. 编译:

解压后,进行目录:
image.png
使用maven命令进行编译:
mvn clean install -Dmaven.test.skip
image.png
编译后目录:
image.png

3. 安装:

拿到elasticsearch-analysis-pinyin-7.16.0.zip 放到elasticsearch/plugins/下面,重启elasticsearch服务;
image.png
image.png

4. 拼音码使用:

4.1创建index

image.png

4.2 关闭index

image.png

4.3 设置settings

image.png

  1. {
  2. "index": {
  3. "analysis": {
  4. "analyzer": {
  5. "pinyin_analyzer": {
  6. "tokenizer": "my_pinyin"
  7. }
  8. },
  9. "tokenizer": {
  10. "my_pinyin": {
  11. "lowercase": "true",
  12. "keep_original": "true",
  13. "remove_duplicated_term": "true",
  14. "keep_separate_first_letter": "false",
  15. "type": "pinyin",
  16. "limit_first_letter_length": "16",
  17. "keep_full_pinyin": "true"
  18. }
  19. }
  20. }
  21. }
  22. }

4.4 创建Mapping

drug_mcs_name/folks/_mapping?include_type_name=true

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

image.png

4.5 关闭重新打开index

drug_mcs_name/_close

image.png

drug_mcs_name/_open

image.png