「Elasticsearch」- 中文拼音分析器 @20210207

该博客介绍了如何在Elasticsearch 7.6.2和6.3.2版本上安装和验证拼音分析器插件,使得搜索关键字可以包含拼音。首先从GitHub下载插件zip文件,然后通过Elasticsearch的bin/elasticsearch-plugin命令进行在线或离线安装,最后重启服务并使用_curl命令验证插件安装成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

拼音分析器:GitHub/medcl/elasticsearch-analysis-pinyin

在搜索关键字中可以包含拼音。

Elasticsearch 7.6.2

第一步、下载插件(可选)

https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.6.2/elasticsearch-analysis-pinyin-7.6.2.zip

第二步、安装插件

在 CentOS 7.4 中,如果使用 YUM 安装 Elasticsearch 服务,则:

#!/bin/sh

cd /usr/share/elasticsearch

# 直接在线安装
./bin/elasticsearch-plugin install \
    "https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.6.2/elasticsearch-analysis-pinyin-7.6.2.zip"

# 或者使用离线(第一步下载的安装包)
./bin/elasticsearch-plugin install "file:///path/to/elasticsearch-analysis-pinyin-7.6.2.zip"

第三步、重启服务

systemctl restart elasticsearch.service

第四步、验证服务

# curl http://10.10.50.233:9200/_cat/plugins
elasticsearch-deve analysis-pinyin 7.6.2

Elasticsearch 6.3.2

# 方法一:直接使用预编译的插件

#!/bin/sh

################################################################################
# 安装
################################################################################
# CentOS 7.4,如果你使用YUM源来安装Elasticsearch服务
cd /usr/share/elasticsearch
./bin/elasticsearch-plugin install \
    "https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.3.2/elasticsearch-analysis-pinyin-6.3.2.zip"

# 版本一定要对应,否则安装会产生类似如下的提示:
# Plugin [analysis-pinyin] was built for Elasticsearch version 6.3.0 but version 6.3.2 is running

################################################################################
# 重启
################################################################################
systemctl restart elasticsearch.service

################################################################################
# 验证
################################################################################
# GET /_cat/plugins
# e8eosG_ analysis-pinyin   6.3.2

# 方法二:使用源码安装(未成功)

#!/bin/sh

################################################################################
# 检查源码并切换到指定的版本
################################################################################
git clone https://github.com/medcl/elasticsearch-analysis-pinyin.git
cd elasticsearch-analysis-pinyin
git checkout tags/v6.3.2 -b v6.3.2

################################################################################
# 修改POM.XML
################################################################################
sed -i 's#<elasticsearch.version>6.3.0</elasticsearch.version>#<elasticsearch.version>6.3.2</elasticsearch.version>#g' pom.xml
sed -i 's#<version>${elasticsearch.version}</version>#<version>6.3.2</version>#g' pom.xml

################################################################################
# 打包
################################################################################
mvn clean package -Delasticsearch.version=6.3.2

################################################################################
# 安装
################################################################################
# CentOS 7.4,如果你使用YUM源来安装Elasticsearch服务
cd /usr/share/elasticsearch
bin/elasticsearch-plugin install \
    "file:///path/to/elasticsearch-analysis-pinyin/target/elasticsearch-analysis-pinyin-6.3.2.jar"

### 未成功的原因 ###
思路是对的,未成功的原因是/src/main/resources/plugin-descriptor.properties中的变量没有被解析,导致在安装生成的Jar时失败。

目前没有找到解析属性文件中变量的命令行选项。

有点头绪:
How do I filter resources based on values from a properties file?
How do I filter resource files to include the values of properties?

# TODO 在MAVEN打包时,动态解析resources/中的属性文件内的变量。

遇到的错误

#1 startOffset must be non-negative,

错误信息:
startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards startOffset=0,endOffset=9,lastStartOffset=6 for field 'xxxxxxx'

解决办法:
"keep_original" : true

参考文献

elasticsearch搜索推荐系列(一)之 ElasticSearch6.2.2安装拼音插件 elasticsearch-analysis-pinyin
Passing command line arguments from Maven as properties in pom.xml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值