0
点赞
收藏
分享

微信扫一扫

elasticsearch 8.x 插件安装(三)之拼音插件

elasticsearch 8.x 插件安装(三)之拼音插件

一、拉取代码

Github地址:https://github.com/infinilabs/analysis-pinyin

image-20241028111157679

二、修改es对应版本

打开elasticsearch目录下的pom文件,将elasticsearch.version版本修改为你需要的版本,此处修改为8.7.0。

image-20241028111225921

点击maven的package命令打包,然后去elasticsearch目录下找到target目录,在release目录下有对应的es插件

image-20241028111334060

image-20241028111458915

三、复制至es plugins目录下

复制到es plugins目录下,并且解压,将原有的名字修改为analysis-pinyin

image-20241028111621621

四、重启es并验证拼音插件

4.1 创建索引

PUT /medcl/ 
{
    "settings" : {
        "analysis" : {
            "analyzer" : {
                "pinyin_analyzer" : {
                    "tokenizer" : "my_pinyin"
                    }
            },
            "tokenizer" : {
                "my_pinyin" : {
                    "type" : "pinyin",
                    "keep_separate_first_letter" : false,
                    "keep_full_pinyin" : true,
                    "keep_original" : true,
                    "limit_first_letter_length" : 16,
                    "lowercase" : true,
                    "remove_duplicated_term" : true
                }
            }
        }
    }
}

4.2 发送一个拼音分词的请求

GET /medcl/_analyze
{
  "text": ["刘德华"],
  "analyzer": "pinyin_analyzer"
}

4.3 返回结果

{
  "tokens" : [
    {
      "token" : "liu",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "de",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "hua",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "刘德华",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 3
    },
    {
      "token" : "ldh",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 4
    }
  ]
}

编程精选网(www.codehuber.com),程序员的终身学习网站已上线!

如果这篇【文章】有帮助到你,希望可以给【JavaGPT】点个赞👍,创作不易,如果有对【后端技术】、【前端领域】感兴趣的小可爱,也欢迎关注❤️❤️❤️ 【JavaGPT】❤️❤️❤️,我将会给你带来巨大的【收获与惊喜】💝💝💝!

本文由博客群发一文多发等运营工具平台 OpenWrite 发布

举报

相关推荐

0 条评论