Elasticsearch07:ES中文分词插件(es-ik)安装部署

这篇具有很好参考价值的文章主要介绍了Elasticsearch07:ES中文分词插件(es-ik)安装部署。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、ES中文分词插件(es-ik)

在中文数据检索场景中,为了提供更好的检索效果,需要在ES中集成中文分词器,因为ES默认是按照英文的分词规则进行分词的,基本上可以认为是单字分词,对中文分词效果不理想。

ES之前是没有提供中文分词器的,现在官方也提供了一些,但是在中文分词领域,IK分词器是不可撼动的,所以在这里我们主要讲一下如何在ES中集成IK这个中文分词器。

1、下载

首先下载es-ik插件,需要到github上下载。

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

Elasticsearch07:ES中文分词插件(es-ik)安装部署
Elasticsearch07:ES中文分词插件(es-ik)安装部署
最终的下载地址为:

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.13.4/elasticsearch-analysis-ik-7.13.4.zip

百度网盘地址:

链接:https://pan.baidu.com/s/1KgBGetSvLpIUPtDz5fUM5Q?pwd=eh35 
提取码:eh35 

注意:在ES中安装IK插件的时候,需要在ES集群的所有节点中都安装。

2、上传

将下载好的elasticsearch-analysis-ik-7.13.4.zip上传到bigdata01的/data/soft/ elasticsearch-7.13.4目录中。

[root@bigdata01 elasticsearch-7.13.4]# ll elasticsearch-analysis-ik-7.13.4.zip 
-rw-r--r--. 1 root root 4504502 Sep  3  2021 elasticsearch-analysis-ik-7.13.4.zip

3、远程拷贝到其他节点

将elasticsearch-analysis-ik-7.13.4.zip远程拷贝到bigdata02和bigdata03上。

[root@bigdata01 elasticsearch-7.13.4]# scp -rq elasticsearch-analysis-ik-7.13.4.zip  bigdata02:/data/soft/elasticsearch-7.13.4
[root@bigdata01 elasticsearch-7.13.4]# scp -rq elasticsearch-analysis-ik-7.13.4.zip  bigdata03:/data/soft/elasticsearch-7.13.4

4、安装

在bigdata01节点离线安装IK插件。

[root@bigdata01 elasticsearch-7.13.4]# bin/elasticsearch-plugin install file:///data/soft/elasticsearch-7.13.4/elasticsearch-analysis-ik-7.13.4.zip 

注意:在安装的过程中会有警告信息提示需要输入y确认继续向下执行。

[=================================================] 100%   
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y

最后看到如下内容就表示安装成功了。

-> Installed analysis-ik
-> Please restart Elasticsearch to activate any plugins installed

注意:插件安装成功之后在elasticsearch-7.13.4的config和plugins目录下会产生一个analysis-ik目录。

config目录下面的analysis-ik里面存储的是ik的配置文件信息。

[root@bigdata01 elasticsearch-7.13.4]# cd config/
[root@bigdata01 config]# ll analysis-ik/
total 8260
-rwxrwxrwx. 1 root root 5225922 Feb 27 20:57 extra_main.dic
-rwxrwxrwx. 1 root root   63188 Feb 27 20:57 extra_single_word.dic
-rwxrwxrwx. 1 root root   63188 Feb 27 20:57 extra_single_word_full.dic
-rwxrwxrwx. 1 root root   10855 Feb 27 20:57 extra_single_word_low_freq.dic
-rwxrwxrwx. 1 root root     156 Feb 27 20:57 extra_stopword.dic
-rwxrwxrwx. 1 root root     625 Feb 27 20:57 IKAnalyzer.cfg.xml
-rwxrwxrwx. 1 root root 3058510 Feb 27 20:57 main.dic
-rwxrwxrwx. 1 root root     123 Feb 27 20:57 preposition.dic
-rwxrwxrwx. 1 root root    1824 Feb 27 20:57 quantifier.dic
-rwxrwxrwx. 1 root root     164 Feb 27 20:57 stopword.dic
-rwxrwxrwx. 1 root root     192 Feb 27 20:57 suffix.dic
-rwxrwxrwx. 1 root root     752 Feb 27 20:57 surname.dic

plugins目录下面的analysis-ik里面存储的是ik的核心jar包。

[root@bigdata01 elasticsearch-7.13.4]# cd plugins/
[root@bigdata01 plugins]# ll analysis-ik/
total 1428
-rwxrwxrwx. 1 root root 263965 Feb 27 20:56 commons-codec-1.9.jar
-rwxrwxrwx. 1 root root  61829 Feb 27 20:56 commons-logging-1.2.jar
-rwxrwxrwx. 1 root root  54626 Feb 27 20:56 elasticsearch-analysis-ik-7.13.4.jar
-rwxrwxrwx. 1 root root 736658 Feb 27 20:56 httpclient-4.5.2.jar
-rwxrwxrwx. 1 root root 326724 Feb 27 20:56 httpcore-4.4.4.jar
-rwxrwxrwx. 1 root root   1807 Feb 27 20:56 plugin-descriptor.properties
-rwxrwxrwx. 1 root root    125 Feb 27 20:56 plugin-security.policy

5、在bigdata02节点离线安装IK插件

[root@bigdata02 elasticsearch-7.13.4]# bin/elasticsearch-plugin install file:///data/soft/elasticsearch-7.13.4/elasticsearch-analysis-ik-7.13.4.zip 

6、在bigdata03节点离线安装IK插件

[root@bigdata03 elasticsearch-7.13.4]# bin/elasticsearch-plugin install file:///data/soft/elasticsearch-7.13.4/elasticsearch-analysis-ik-7.13.4.zip 

7、如果集群正在运行,则需要停止集群

在bigdata01上停止。

[root@bigdata01 elasticsearch-7.13.4]# jps
1680 Elasticsearch
2047 Jps
[root@bigdata01 elasticsearch-7.13.4]# kill 1680

在bigdata02上停止。

[root@bigdata02 elasticsearch-7.13.4]# jps
1682 Elasticsearch
1866 Jps
[root@bigdata02 elasticsearch-7.13.4]# kill 1682

在bigdata03上停止。

[root@bigdata03 elasticsearch-7.13.4]# jps
1683 Elasticsearch
1803 Jps
[root@bigdata03 elasticsearch-7.13.4]# kill 1683

8、修改目录权限

修改elasticsearch-7.13.4的plugins目录下analysis-ik子目录的权限
直接修改elasticsearch-7.13.4目录的权限即可。

在bigdata01上执行。

[root@bigdata01 elasticsearch-7.13.4]# cd ..
[root@bigdata01 soft]# chmod -R 777 elasticsearch-7.13.4

在bigdata02上执行。

[root@bigdata02 elasticsearch-7.13.4]# cd ..
[root@bigdata02 soft]# chmod -R 777 elasticsearch-7.13.4

在bigdata03上执行。

[root@bigdata03 elasticsearch-7.13.4]# cd ..
[root@bigdata03 soft]# chmod -R 777 elasticsearch-7.13.4

9、重新启动ES集群

在bigdata01上执行。

[root@bigdata01 soft]# su es
[es@bigdata01 soft]$ cd /data/soft/elasticsearch-7.13.4
[es@bigdata01 elasticsearch-7.13.4]$ bin/elasticsearch -d

在bigdata02上执行。

[root@bigdata02 soft]# su es
[es@bigdata02 soft]$ cd /data/soft/elasticsearch-7.13.4
[es@bigdata02 elasticsearch-7.13.4]$ bin/elasticsearch -d

在bigdata03上执行。

[root@bigdata03 soft]# su es
[es@bigdata03 soft]$ cd /data/soft/elasticsearch-7.13.4
[es@bigdata03 elasticsearch-7.13.4]$ bin/elasticsearch -d

10、验证IK的分词效果

首先使用默认分词器测试中文分词效果。

[root@bigdata01 soft]# curl -H "Content-Type: application/json" -XPOST  'http://bigdata01:9200/emp/_analyze?pretty' -d '{"text":"我们是中国人"}'
{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "<IDEOGRAPHIC>",
      "position" : 0
    },
    {
      "token" : "们",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "<IDEOGRAPHIC>",
      "position" : 1
    },
    {
      "token" : "是",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "<IDEOGRAPHIC>",
      "position" : 2
    },
    {
      "token" : "中",
      "start_offset" : 3,
      "end_offset" : 4,
      "type" : "<IDEOGRAPHIC>",
      "position" : 3
    },
    {
      "token" : "国",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "<IDEOGRAPHIC>",
      "position" : 4
    },
    {
      "token" : "人",
      "start_offset" : 5,
      "end_offset" : 6,
      "type" : "<IDEOGRAPHIC>",
      "position" : 5
    }
  ]
}

然后使用IK分词器测试中文分词效果。

[root@bigdata01 soft]# curl -H "Content-Type: application/json" -XPOST  'http://bigdata01:9200/emp/_analyze?pretty' -d '{"text":"我们是中国人","tokenizer":"ik_max_word"}'
{
  "tokens" : [
    {
      "token" : "我们",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "中国人",
      "start_offset" : 3,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "中国",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "国人",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 4
    }
  ]
}

在这里我们发现分出来的单词里面有一个 是,这个单词其实可以认为是一个停用词,在分词的时候是不需要切分出来的。
在这被切分出来了,那也就意味着在进行停用词过滤的时候没有过滤掉。

针对ik这个词库而言,它的停用词词库里面都有哪些单词呢?

[root@bigdata01 elasticsearch-7.13.4]# cd config/analysis-ik/
[root@bigdata01 analysis-ik]# ll
total 8260
-rwxrwxrwx. 1 root root 5225922 Feb 27 20:57 extra_main.dic
-rwxrwxrwx. 1 root root   63188 Feb 27 20:57 extra_single_word.dic
-rwxrwxrwx. 1 root root   63188 Feb 27 20:57 extra_single_word_full.dic
-rwxrwxrwx. 1 root root   10855 Feb 27 20:57 extra_single_word_low_freq.dic
-rwxrwxrwx. 1 root root     156 Feb 27 20:57 extra_stopword.dic
-rwxrwxrwx. 1 root root     625 Feb 27 20:57 IKAnalyzer.cfg.xml
-rwxrwxrwx. 1 root root 3058510 Feb 27 20:57 main.dic
-rwxrwxrwx. 1 root root     123 Feb 27 20:57 preposition.dic
-rwxrwxrwx. 1 root root    1824 Feb 27 20:57 quantifier.dic
-rwxrwxrwx. 1 root root     164 Feb 27 20:57 stopword.dic
-rwxrwxrwx. 1 root root     192 Feb 27 20:57 suffix.dic
-rwxrwxrwx. 1 root root     752 Feb 27 20:57 surname.dic
[root@bigdata01 analysis-ik]# more stopword.dic 
a
an
and
are
as
at
be
but
by
for
if
in
into
is
it
no
not
of
on
or

ik的停用词词库是stopword.dic这个文件,这个文件里面目前都是一些英文停用词。
我们可以手工在这个文件中把中文停用词添加进去,先添加 是 这个停用词。

[root@bigdata01 analysis-ik]# vi stopword.dic 
.....
是

然后把这个文件的改动同步到集群中的所有节点上。

[root@bigdata01 analysis-ik]# scp -rq stopword.dic bigdata02:/data/soft/elasticsearch-7.13.4/config/analysis-ik/
[root@bigdata01 analysis-ik]# scp -rq stopword.dic bigdata03:/data/soft/elasticsearch-7.13.4/config/analysis-ik/

重启集群让配置生效。
先停止bigdata01、bigdata02、bigdata03上的ES服务。

[root@bigdata01 analysis-ik]# jps
3051 Elasticsearch
3358 Jps
[root@bigdata01 analysis-ik]# kill 3051

[root@bigdata02 analysis-ik]$ jps
2496 Elasticsearch
2570 Jps
[root@bigdata02 analysis-ik]$ kill 2496

[root@bigdata03 analysis-ik]$ jps
2481 Jps
2412 Elasticsearch
[root@bigdata03 analysis-ik]$ kill 2412

启动bigdata01、bigdata02、bigdata03上的ES服务。

[es@bigdata01 elasticsearch-7.13.4]$ bin/elasticsearch -d

[es@bigdata02 elasticsearch-7.13.4]$ bin/elasticsearch -d

[es@bigdata03 elasticsearch-7.13.4]$ bin/elasticsearch -d

再使用IK分词器测试一下中文分词效果。

[root@bigdata01 analysis-ik]# curl -H "Content-Type: application/json" -XPOST  'http://bigdata01:9200/test/_analyze?pretty' -d '{"text":"我们是中国人","tokenizer":"ik_max_word"}'
{
  "tokens" : [
    {
      "token" : "我们",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "中国人",
      "start_offset" : 3,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "中国",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "国人",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 3
    }
  ]
}

此时再查看会发现没有"是" 这个单词了,相当于在过滤停用词的时候把它过滤掉了。文章来源地址https://www.toymoban.com/news/detail-435155.html

到了这里,关于Elasticsearch07:ES中文分词插件(es-ik)安装部署的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • es安装中文分词器 IK

    1.下载 https://github.com/medcl/elasticsearch-analysis-ik 这个是官方的下载地址,下载跟自己es版本对应的即可 那么需要下载 7.12.0版本的分词器 2.安装 1.在es的 plugins 的文件夹下先创建一个ik目录 bash cd /home/apps/elasticsearch/plugins/ mkdir ik 2.然后将下载解压后的文件放入到ik文件夹下 3.重启

    2024年02月21日
    浏览(31)
  • docker-compose安装es以及ik分词同义词插件

    目录 1 前言 2 集成利器Docker 2.1 Docker环境安装 2.1.1 环境检查 2.1.2 在线安装 2.1.3 离线安装 2.2 Docker-Compose的安装 2.2.1 概念简介 2.2.2 安装步骤 2.2.2.1 二进制文件安装 2.2.2.2 离线安装 2.2.2.3 yum安装 3 一键安装ES及Kibana 3.1 yml文件的编写 3.1.1 elasticsearch.yml配置 3.1.2 kibana.yml配置 3.2 一键

    2024年04月23日
    浏览(32)
  • 搜索引擎elasticsearch :安装elasticsearch (包含安装组件kibana、IK分词器、部署es集群)

    kibana可以帮助我们方便地编写DSL语句,所以还要装kibana 因为我们还需要部署kibana容器,因此需要让es和kibana容器互联。这里先创建一个网络: 这里我们采用elasticsearch的7.12.1版本的镜像,这个镜像体积非常大,接近1G。不建议大家自己pull。 课前资料提供了镜像的tar包: 大家将

    2024年02月16日
    浏览(43)
  • Docker安装ElasticSearch、Kibana、IK分词器以及设置ES账户密码

    版本声明: 系统 :CentOS 7.9(云服务器) ES版本 :7.6.1 Kibana :7.6.1 Ik分析器版本 :7.6.1 1、拉取镜像 2、创建挂载目录 设置所有用户读写执行权限 : sudo chmod -R 777 /docker_config/elasticsearch/ 3、创建elasticsearch.yml 配置文件 4、创建容器 参数说明 : -p 端口映射 -e discovery.type=single

    2023年04月09日
    浏览(56)
  • Linux下安装ElasticSearch-analysis-ik中文分词器插件,以及可能出现的异常处理

            注意:安装可以采用在线方式、离线方式,但是不建议在线安装,速度超级慢,本文只介绍离线安装方式                 下载地址:https://github.com/medcl/elasticsearch-analysis-ik                 切记选择版本需要跟ElasticSearch保持一致,否则可能会出现一些未知的异

    2024年02月07日
    浏览(50)
  • ElasticSearch的使用,安装ik分词器,自定义词库,SpringBoot整合ES(增、删、改、查)

    保存一个数据,保存在哪个索引的哪个类型下,指定用哪个唯一标识(相当于,保存一个数据,保存在那个数据库中的哪个表中,指定主键ID) 例:PUT customer/external/1;在customer索引下的external类型下保存1号数据name为John Doe的数据 POST和PUT都可以新增数据 注意: POST 新增。如果

    2023年04月25日
    浏览(39)
  • es笔记四之中文分词插件安装与使用

    本文首发于公众号:Hunter后端 原文链接:es笔记四之中文分词插件安装与使用 前面我们介绍的操作及演示都是基于英语单词的分词,但我们大部分使用的肯定都是中文,所以如果需要使用分词的操作肯定也是需要使用中分分词。 这里我们介绍一下如何安装中文分词插件。 在

    2024年02月05日
    浏览(34)
  • Elasticsearch安装分词插件[ES系列] - 第499篇

    历史文章( 文章 累计490+) 《 国内最全的Spring Boot系列之一 》 《 国内最全的Spring Boot系列之二 》 《 国内最全的Spring Boot系列之三 》 《 国内最全的Spring Boot系列之四 》 《 国内最全的Spring Boot系列之 五 》 《 国内最全的Spring Boot系列之六 》 ElasticSearch应用场景以及技术

    2024年02月02日
    浏览(29)
  • elasticsearch 安装 IK 中文分词器插件提示找不到文件的异常(Exception in thread “main“ java.nio.file.NoSuchFileException)

    错误截图 在命令行窗口,执行如下命令安装 IK 中文分词器 失败。 错误日志 1、自己到github下载对应版本的ik中文分词器 上面命令中两个插件版本号应该和 Elasticsearch 的版本保持一致,我现在用的是 7.14.1 版本。 首先版本和命令是对得上的。 命令行窗口通过命令下载失败的话

    2024年04月11日
    浏览(42)
  • es安装ik分词器

    IK分词器下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases 下载ES版本对应的分词器即可 安装ik分词器 将下载好的zip包解压,生成一个ik文件夹 将ik文件夹移动到ES安装目录下的 plugins 文件夹下(每台ES节点都要执行相同的操作) 重启ES集群 自定义分词库 用 vim 在ik中的

    2023年04月10日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包