elasticsearch7.5.1集群安装elasticsearch-jieba-plugin 7.4.2

/ 随笔 / 110浏览

elasticsearch7.5.1集群安装elasticsearch-jieba-plugin 7.4.2

安装插件需要在集群的其中一个节点安装后重启es程序,没有问题后拷贝到其他节点重启后生效

安装gradle

下载gradle的二进制文件

wget https://services.gradle.org/distributions/gradle-6.3-bin.zip
cd /usr/local/elk

修改环境变量将gradle加入环境变量中

vim /etc/profile
export GRADLE_HOME=/usr/local/elk/gradle-6.3/
export PATH=$GRADLE_HOME/bin:$PATH
source /etc/profile

编译生成jieba分词插件

> gradle pz
Welcome to Gradle 6.3!

Here are the highlights of this release:

 - Java 14 support
 - Improved error messages for unexpected failures

For more details see https://docs.gradle.org/6.3/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 3m 23s
4 actionable tasks: 4 executed

将最终编译生成的elasticsearch-jieba-plugin-7.4.2.zip拷贝到es插件目录中

cp /build/distributions/elasticsearch-jieba-plugin-7.4.2.zip /elasticsearch-7.5.1/plugins/
cd /elasticsearch-7.5.1/plugins/
unzip -d jieba elasticsearch-jieba-plugin-7.4.2.zip

修改jieba配置,因为没有最新的 jieba 7.5.1 插件,直接修改配置即可

vim /plugin-descriptor.properties
description=A jieba analysis of plugins for Elasticsearch

version=7.5.1
name=jieba
classname=org.elasticsearch.plugin.analysis.jieba.AnalysisJiebaPlugin
java.version=8

elasticsearch.version=7.5.1

重新启动elasticsearch

./elasticsearch

测试

curl -H "Content-Type: application/json" -u elastic:pass -XPOST http://10.10.17.19:9200/_analyze -d '{"analyzer" : "jieba_index", "text" : "你好,世界,很高兴认识你!"}'
{
    "tokens":[
        {
            "token":"你好",
            "start_offset":0,
            "end_offset":2,
            "type":"word",
            "position":0
        },
        {
            "token":",",
            "start_offset":2,
            "end_offset":3,
            "type":"word",
            "position":1
        },
        {
            "token":"世界",
            "start_offset":3,
            "end_offset":5,
            "type":"word",
            "position":2
        },
        {
            "token":",",
            "start_offset":5,
            "end_offset":6,
            "type":"word",
            "position":3
        },
        {
            "token":"很",
            "start_offset":6,
            "end_offset":7,
            "type":"word",
            "position":4
        },
        {
            "token":"高兴",
            "start_offset":7,
            "end_offset":9,
            "type":"word",
            "position":5
        },
        {
            "token":"认识",
            "start_offset":9,
            "end_offset":11,
            "type":"word",
            "position":6
        },
        {
            "token":"你",
            "start_offset":11,
            "end_offset":12,
            "type":"word",
            "position":7
        },
        {
            "token":"!",
            "start_offset":12,
            "end_offset":13,
            "type":"word",
            "position":8
        }
    ]
}

写在最后

如果是集群,需要将jieba这个插件拷贝到其他节点

scp -r jieba root@host1:/elasticsearch-7.5.1/plugins/