Java开发环境系列:全文搜索引擎elasticsearch(ik分词器)

2019-08-06 17:14:42 浏览数 (1)

elasticsearch安装ik分词器(非极速版)

方式一:

安装中文分词插件,在elasticsearch-6.2.2bin目录下执行以下命令: 

elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip

方式二:

1、下载

下载地址为:

https://github.com/medcl/elasticsearch-analysis-ik

2、解压

把下载的 elasticsearch-analysis-ik.

zip解压。

3、Maven打包

进入elasticsearch-analysis-ik-master/ 下,打包。注意:打包后的文件在elasticsearch-analysis-ik-master/target/目录下。

打包命令:

mvn clean package

4、创建目录ik

cd elasticsearch-2.2.0/plugins

mkdir ik

cd ik

然后将打包后的elasticsearch-analysis-ik-1.8.0.jar 放入当前目录下,然后解压。

5、设置

2.0以上可以不设置,我没有设置,在Elasticsearch的config下的elasticsearch.yml文件中,添加如下代码。

或者简单配置:

index.analysis.analyzer.ik.type : “ik”

6、启动测试

elasticsearch安装ik分词器(极速版)

简介:

下面讲有我已经打包并且编辑过的zip包,你可以在下面下载即可。

1、下载zip包。

elasticsearch-analysis-ik-1.8.0.jar

下面有附件链接【ik-安装包.zip】,下载即可。(内有做好的elasticsearch-analysis-ik-1.8.0.jar)

2、上传zip包。

下载ik.zip文件后解压缩,如下图。

修改plugin-descriptor.properties文件,将elasticsearch.version=2.2.0改成自己的elasticsearch版本(通过访问localhost:9200查看版本号)

#把这个版本号改成你对应的版本即可,如你的版本是2.2.0,就改成2.2.0

elasticsearch.version=2.2.0

修改好后,打成zip包上传至Linux系统elasticsearch-2.2.0/plugins目录下,使用unzip ik.zip解压

此处注意目录结构必须是这样,如下图:

3、启动测试

呃,我们发现报错了。

[elasticsearch@iZ25x3wjytdZ elasticsearch-2.0.0]$ ./bin/elasticsearch

[2016-03-01 10:32:02,958][INFO ][node ] [Landslide] version[2.0.0], pid[11109], build[de54438/2015-10-22T08:09:48Z]

[2016-03-01 10:32:02,959][INFO ][node ] [Landslide] initializing ...

Exception in thread "main" java.lang.IllegalStateException: Unable to initialize plugins

Likely root cause: java.nio.file.FileSystemException: /home/elasticsearch/es/elasticsearch-2.0.0/plugins/ik.zip/plugin-descriptor.properties: Not a directory

at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)

at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)

at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)

at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)

at java.nio.file.Files.newByteChannel(Files.java:317)

at java.nio.file.Files.newByteChannel(Files.java:363)

at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:380)

at java.nio.file.Files.newInputStream(Files.java:108)

at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:86)

at org.elasticsearch.plugins.PluginsService.getPluginBundles(PluginsService.java:306)

at org.elasticsearch.plugins.PluginsService.(PluginsService.java:112)

at org.elasticsearch.node.Node.(Node.java:144)

at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)

at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)

at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

一看我们就知道,他去找plugins/ik.zip 下的配置文件对吧。解决方案是把这个ZIP包删除即可。删除后再次启动。

[elasticsearch@iZ25x3wjytdZ elasticsearch-2.0.0]$ ./bin/elasticsearch

[2016-03-01 10:32:02,958][INFO ][node ] [Landslide] version[2.0.0], pid[11109], build[de54438/2015-10-22T08:09:48Z]

[2016-03-01 10:32:02,959][INFO ][node ] [Landslide] initializing ...

Exception in thread "main" java.lang.IllegalStateException: Unable to initialize plugins

Likely root cause: java.nio.file.FileSystemException: /home/elasticsearch/es/elasticsearch-2.0.0/plugins/ik.zip/plugin-descriptor.properties: Not a directory

at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)

at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)

at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)

at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)

at java.nio.file.Files.newByteChannel(Files.java:317)

at java.nio.file.Files.newByteChannel(Files.java:363)

at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:380)

at java.nio.file.Files.newInputStream(Files.java:108)

at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:86)

at org.elasticsearch.plugins.PluginsService.getPluginBundles(PluginsService.java:306)

at org.elasticsearch.plugins.PluginsService.(PluginsService.java:112)

at org.elasticsearch.node.Node.(Node.java:144)

at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)

at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)

at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

我们从启动就看的出来,IK分词器安装成功。

[2016-03-01 10:34:28,803][INFO ][plugins ] [Big Wheel] loaded [analysis-ik], sites [head]

测试:

http://123.57.163.79:9200/_analyze?analyzer=ik&pretty=true&text=sojson

0 人点赞