首页 > 其他分享 >elasticsearch: 安装ik中文分词(es 8.14.2)

elasticsearch: 安装ik中文分词(es 8.14.2)

时间:2024-07-11 11:19:58浏览次数:14  
标签:end token start ik elasticsearch offset 8.14 type

一,测试分词命令:

1,查看已安装的插件:

[lhdop@blog ~]$ curl -X GET "localhost:9200/_cat/plugins?v&s=component"
name component version

2,standard分词

[lhdop@blog ~]$ curl -X GET "localhost:9200/_analyze?pretty" -H 'Content-Type: application/json' -d'
> {
  "analyzer": "standard",
  "text": "Text to analyze"
}
'
{
  "tokens" : [
    {
      "token" : "text",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "to",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "analyze",
      "start_offset" : 8,
      "end_offset" : 15,
      "type" : "<ALPHANUM>",
      "position" : 2
    }
  ]
}

2, 从命令行安装smartcn分词插件:

[lhdop@blog bin]$ ./elasticsearch-plugin install analysis-smartcn
warning: ignoring JAVA_HOME=/usr/local/soft/jdk-17.0.11; using ES_JAVA_HOME
-> Installing analysis-smartcn
-> Downloading analysis-smartcn from elastic
[=================================================] 100%  
-> Installed analysis-smartcn
-> Please restart Elasticsearch to activate any plugins installed

3,smartcn安装到了plugins目录下,查看文件:

[lhdop@blog elasticsearch-8.14.2]$ ls plugins/analysis-smartcn/
analysis-smartcn-8.14.2.jar  lucene-analysis-smartcn-9.10.0.jar  plugin-descriptor.properties

安装完后,如果想让插件生效,需要重启elasticsearch服务

关闭

[root@blog ~]# kill 260903

启动:

[root@blog ~]# /usr/local/soft/elasticsearch-8.14.2/bin/elasticsearch -d 

4,试用smartcn分词,效果不怎么理想,把'海鲜味'给分成了'海'和'鲜味'两个词

[lhdop@blog elasticsearch-8.14.2]$ curl -X GET "localhost:9200/_analyze?pretty" -H 'Content-Type: application/json' -d'
{
  "analyzer": "smartcn",
  "text": "这是一碗海鲜味方便面"
}
'
{
  "tokens" : [
    {
      "token" : "这",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "一",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "碗",
      "start_offset" : 3,
      "end_offset" : 4,
      "type" : "word",
      "position" : 3
    },
    {
      "token" : "海",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "word",
      "position" : 4
    },
    {
      "token" : "鲜味",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "word",
      "position" : 5
    },
    {
      "token" : "方便面",
      "start_offset" : 7,
      "end_offset" : 10,
      "type" : "word",
      "position" : 6
    }
  ]
}

5,查看已安装的插件,已经可以看到安装后的smartcn插件了:

[lhdop@blog elasticsearch-8.14.2]$ curl -X GET "localhost:9200/_cat/plugins?v&s=component"
name                    component        version
iZ2zejc9t0hf6pnw6sewrxZ analysis-smartcn 8.14.2

二,ik分词插件安装

1,github地址

https://github.com/infinilabs/analysis-ik/releases

2,官网:

https://release.infinilabs.com/analysis-ik/stable/

3,查看本地es的版本:

[lhdop@blog ~]$ /usr/local/soft/elasticsearch-8.14.2/bin/elasticsearch --version
warning: ignoring JAVA_HOME=/usr/local/soft/jdk-17.0.11; using ES_JAVA_HOME
Version: 8.14.2, Build: tar/2afe7caceec8a26ff53817e5ed88235e90592a1b/2024-07-01T22:06:58.515911606Z, JVM: 17.0.11

4, 安装支持的elasticsearch版本地址:

说明:ik的版本是要和es的版本严格对应的,否则可能会导致安装或运行报错

[lhdop@blog elasticsearch-8.14.2]$ bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.14.2
warning: ignoring JAVA_HOME=/usr/local/soft/jdk-17.0.11; using ES_JAVA_HOME
-> Installing https://get.infini.cloud/elasticsearch/analysis-ik/8.14.2
-> Downloading https://get.infini.cloud/elasticsearch/analysis-ik/8.14.2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See https://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

5,重启服务:

关闭

[root@blog ~]# kill 264687

启动:

[root@blog ~]# /usr/local/soft/elasticsearch-8.14.2/bin/elasticsearch -d 

6,安装完成后查看插件列表

[lhdop@blog elasticsearch-8.14.2]$ ./bin/elasticsearch-plugin list
warning: ignoring JAVA_HOME=/usr/local/soft/jdk-17.0.11; using ES_JAVA_HOME
analysis-ik
analysis-smartcn

 

三,测试效果

1,两种分词方式

ik中文分词效果

ik分词插件支持 ik_smart 和 ik_max_word 两种分词器

ik_smart - 粗粒度的分词
ik_max_word - 会尽可能的枚举可能的关键词,就是分词比较细致一些,会分解出更多的关键词

2,测试ik_smart分词器:

[lhdop@blog elasticsearch-8.14.2]$ curl -X GET "localhost:9200/_analyze?pretty" -H 'Content-Type: application/json' -d'
{
  "analyzer": "ik_smart",
  "text": "这是一碗海鲜味方便面"
}
> '
{
  "tokens" : [
    {
      "token" : "这是",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "一碗",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "海",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "CN_CHAR",
      "position" : 2
    },
    {
      "token" : "鲜味",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "方便面",
      "start_offset" : 7,
      "end_offset" : 10,
      "type" : "CN_WORD",
      "position" : 4
    }
  ]
} 

3,测试ik_max_word分词器:

[lhdop@blog elasticsearch-8.14.2]$ curl -X GET "localhost:9200/_analyze?pretty" -H 'Content-Type: application/json' -d'
{
  "analyzer": "ik_max_word",
  "text": "这是一碗海鲜味方便面"
}'
{
  "tokens" : [
    {
      "token" : "这是",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "一碗",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "一",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "TYPE_CNUM",
      "position" : 2
    },
    {
      "token" : "碗",
      "start_offset" : 3,
      "end_offset" : 4,
      "type" : "COUNT",
      "position" : 3
    },
    {
      "token" : "海鲜",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "鲜味",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "方便面",
      "start_offset" : 7,
      "end_offset" : 10,
      "type" : "CN_WORD",
      "position" : 6
    },
    {
      "token" : "方便",
      "start_offset" : 7,
      "end_offset" : 9,
      "type" : "CN_WORD",
      "position" : 7
    },
    {
      "token" : "面",
      "start_offset" : 9,
      "end_offset" : 10,
      "type" : "CN_CHAR",
      "position" : 8
    }
  ]
}

 

四,查看es版本

[lhdop@blog ~]$ /usr/local/soft/elasticsearch-8.14.2/bin/elasticsearch --version
warning: ignoring JAVA_HOME=/usr/local/soft/jdk-17.0.11; using ES_JAVA_HOME
Version: 8.14.2, Build: tar/2afe7caceec8a26ff53817e5ed88235e90592a1b/2024-07-01T22:06:58.515911606Z, JVM: 17.0.11

 

标签:end,token,start,ik,elasticsearch,offset,8.14,type
From: https://www.cnblogs.com/architectforest/p/18295458

相关文章

  • MUNIK解读ISO26262 : 硬件架构评估及FMEDA(系统级)
    前言功能安全领域硬件层面的核心安全活动---FMEDA(FailureModesEffectsandDiagnosticAnalysis)一直受到功能安全工程师的广泛关注!作为定量分析的安全分析方法,FMEDA涉及到了复杂的计算公式和大范围的数据处理。为何做FMEDA汽车功能安全关注汽车电子/电气系统功能的正确、......
  • 一文带你快速了解项目ASPICE评估的那些事-MUNIK
    01、摘要随着汽车电动化、智能化和互联化不断演进,汽车的电子电气架构得到持续升级,而汽车硬件方面逐渐趋向标准化。与此同时,汽车软件呈现出不断多样化和日益复杂的趋势。在这个大背景下,传统的软件开发流程已经无法满足这一需求,我们需要建立一套合理的软件开发体系,以更好地应对......
  • 认识R155法规(UN Regulation No. 155)-MUNIK
    背景Background随着汽车新四化(电动化、智能化、网联化、共享化)政策的提出,大数据和人工智能等技术的发展,以及软件驱动汽车、舱驾一体、行泊一体等新型架构概念的提出,车内外智能传感器采集的大量数据(包括驾驶员,乘客,车外道路交通环境等)通过通信网络(比如5G蜂窝移动)实时与外部世界......
  • MUNIK解读ISO26262--系统架构
    功能安全之系统阶段-系统架构我们来浅析下功能安全系统阶段重要话题——“系统架构”目录概览:系统架构的作用系统架构类型系统架构层级的相关安全机制梳理1.系统架构的作用架构的思维包括抽象思维、分层思维、结构化思维和演化思维。通过将复杂系统分解为小的单元来简化......
  • TikTok小店推出“百万英镑俱乐部”,实力宠卖家!
    TikTokShop近期在英国市场重磅推出了“百万英镑俱乐部”激励计划,这一举措旨在通过一系列诱人福利,助力商家在TikTok平台上实现销售飞跃。该计划不仅彰显了TikTokShop对于商家成长的深切关怀,更以实际行动诠释了“实力宠卖家”的承诺。我们一起来深入剖析这五大核心优势:1、......
  • Pyodps2节点连接linux服务器(paramiko 检查文件是否存在)
    在maxcomputer加入paramiko相关资源包1#!/usr/bin/python2#-*-coding:UTF-8-*-34##@resource_reference{"six.zip"}5##@resource_reference{"PyNaCl-1.4.0.zip"}6##@resource_reference{"paramiko-2.7.2.zip"}7##@resource_r......
  • K8S学习教程(三):在PetaExpress KubeSphere 容器部署 Wiki 系统 wiki.js 并启用中文全
      背景wiki.js是非常优秀的开源Wiki系统,尽管在与xwiki功能相比,还不算完善,但也在不断进步。常用的功能还是比较实用的,如:Wiki写作、分享、权限管理功能还是非常实用的,UI设计非常的漂亮,精美的界面和直观的操作体验,能够满足小团队的基本知识管理需求。认真阅读......
  • 编译安装Kubernetes 1.29 高可用集群(8)--Dashboard和Traefik安装部署
    1.部署Dashboard1.1在任意k8s-master节点上安装dashboard#helmrepoaddkubernetes-dashboardhttps://kubernetes.github.io/dashboard/#helmupgrade--installkubernetes-dashboardkubernetes-dashboard/kubernetes-dashboard--create-namespace--namespacekuberne......
  • ElasticSearch系列---【在已有索引中添加新的字段】
    1.问题描述消费kafka的数据,写入es,为了查看推送时间和消费时间的时间差值,我们需要在原有的es索引core_pri_flow_202405中添加新字段produce_time和create_time。2.直接使用devtools添加新字段#使用Easy-Es框架,实体类中添加字段@IndexField(value="produce_time",fieldType=Fie......
  • Elasticsearch:Node.js ECS 日志记录 - Pino
    在我的上一篇文章“Beats:使用Filebeat从Python应用程序中提取日志”里,我详述了如何使用Python来生成日志,并使用Filebeat来收集日志到Elasticsearch中。在今天的文章中,我来详细描述如何使用Node.js来生成ECS相兼容的日子。ECS相兼容的日志符合易于Elasticsear......