Elasticsearch安装IK分词器(本博第一篇)

2023-12-25 13:18

本文主要是介绍Elasticsearch安装IK分词器(本博第一篇),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转自:Elasticsearch安装IK分词器

安装方式大概分为两种:

  1. 自行编译;
  2. 使用elasticsearch-rtf版,利用别人编译好的文件进行安装;

环境说明:

我下载的es版本是:elasticsearch-1.7.4.tar.gz,这里我是用的ik版本是elasticsearch-rtf-1.0.0.zip解压后得到的elasticsearch-analysis-ik-1.2.6.jar文件。

方式一:自行编译

自行编译的步骤如下:

1.到https://github.com/medcl/elasticsearch-analysis-ik页面下载elasticsearch-analysis-ik-x.x.x.zip压缩包;
2.解压elasticsearch-analysis-ik-x.x.x.zip,然后进行elasticsearch-analysis-ik-x.x.x目录;
3.使用maven进行打包,得到elasticsearch-analysis-ik-x.x.x.jar(然而我并不会使用maven进行打包,所以我没用这种方式);
4.进行elasticsearch-1.7.4/plugins目录,创建目录analysis-ik,并把你编译好的elasticsearch-analysis-ik-x.x.x.jar放置到此目录;
5.将你下载的elasticsearch-analysis-ik-x.x.x.zip解压后的config目录下的ik目录复制到elasticsearch-1.7.4/config目录;
6.配置elasticsearch-1.7.4/config目录下的elasticsearch.yml文件,在文件尾部加入如下代码:

index:  analysis:                     analyzer:        ik:  alias: [ik_analyzer]  type: org.elasticsearch.index.analysis.IkAnalyzerProvider  ik_max_word:  type: ik  use_smart: false  ik_smart:  type: ik  use_smart: true

或简单配置:

index.analysis.analyzer.ik.type : "ik"

7.重新启动es;

方式二:使用elasticsearch-rtf版,利用别人编译好的文件进行安装

我使用的就是这种方式,第一种方式我并没有进行测试,所以暂时不保证正确,着重说明一下第二种方式,步骤如下:

1.到这里https://github.com/medcl/elasticsearch-rtf/releases下载rtf版的es,我下载的是elasticsearch-rtf-1.0.0.zip;
2.解压elasticsearch-rtf-1.0.0.zip压缩包;
3.将elasticsearch-rtf-1.0.0/plugins/analysis-ik目录,复制到elasticsearch-1.7.4/plugins得到elasticsearch-1.7.4/plugins/analysis-ik;
4.将elasticsearch-rtf-1.0.0/config/ik复制到elasticsearch-1.7.4/config/得到elasticsearch-1.7.4/config/ik;
5.编辑elasticsearch-1.7.4/config/elasticsearch.yml文件,在文件尾部加入以下内容:

index:  analysis:                     analyzer:        ik:  alias: [ik_analyzer]  type: org.elasticsearch.index.analysis.IkAnalyzerProvider  ik_max_word:  type: ik  use_smart: false  ik_smart:  type: ik  use_smart: true

或简单配置:

index.analysis.analyzer.ik.type : "ik"

6.重新启动es;

测试(我在第二种安装方式下进行的测试)

创建索引:

curl -XPUT http://localhost:9200/index

创建映射:

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{"fulltext": {"_all": {"analyzer": "ik_max_word","search_analyzer": "ik_max_word","term_vector": "no","store": "false"},"properties": {"content": {"type": "string","store": "no","term_vector": "with_positions_offsets","analyzer": "ik_max_word","search_analyzer": "ik_max_word","include_in_all": "true","boost": 8}}}
}'

为索引添加一些内容:

curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/index/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'

进行高亮查询:

curl -XPOST http://localhost:9200/index/fulltext/_search  -d'
{"query" : { "term" : { "content" : "中国" }},"highlight" : {"pre_tags" : ["<tag1>", "<tag2>"],"post_tags" : ["</tag1>", "</tag2>"],"fields" : {"content" : {}}}
}
'

查询结果:

{"took":31,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":0.61370564,"hits":[{"_index":"index","_type":"fulltext","_id":"4","_score":0.61370564,"_source":
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
,"highlight":{"content":["<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"]}},{"_index":"index","_type":"fulltext","_id":"3","_score":0.61370564,"_source":
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
,"highlight":{"content":["中韩渔警冲突调查:韩警平均每天扣1艘<tag1>中国</tag1>渔船"]}}]}}

或者你可以直接在浏览器地址栏进行测试:http://localhost:9200/index/_analyze?analyzer=ik&pretty=true&text=%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA

注意:如果你的版本不对应,可能会出现如下错误:

{"error":"IndexCreationException[[index] failed to create index]; nested: ElasticsearchIllegalArgumentException[failed to find analyzer type [ik] or tokenizer for [ik_max_word]]; nested: NoClassSettingsException[Failed to load class setting [type] with value [ik]]; nested: ClassNotFoundException[org.elasticsearch.index.analysis.ik.IkAnalyzerProvider]; ","status":400}

参考文章:

1.http://samchu.logdown.com/posts/277928-elasticsearch-chinese-word-segmentation;
2.https://github.com/medcl/elasticsearch-analysis-ik;

这篇关于Elasticsearch安装IK分词器(本博第一篇)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/535655

相关文章

mac安装nvm(node.js)多版本管理实践步骤

《mac安装nvm(node.js)多版本管理实践步骤》:本文主要介绍mac安装nvm(node.js)多版本管理的相关资料,NVM是一个用于管理多个Node.js版本的命令行工具,它允许开发者在... 目录NVM功能简介MAC安装实践一、下载nvm二、安装nvm三、安装node.js总结NVM功能简介N

python安装whl包并解决依赖关系的实现

《python安装whl包并解决依赖关系的实现》本文主要介绍了python安装whl包并解决依赖关系的实现,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录一、什么是whl文件?二、我们为什么需要使用whl文件来安装python库?三、我们应该去哪儿下

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

MySQL8.2.0安装教程分享

《MySQL8.2.0安装教程分享》这篇文章详细介绍了如何在Windows系统上安装MySQL数据库软件,包括下载、安装、配置和设置环境变量的步骤... 目录mysql的安装图文1.python访问网址2javascript.点击3.进入Downloads向下滑动4.选择Community Server5.

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

MySql9.1.0安装详细教程(最新推荐)

《MySql9.1.0安装详细教程(最新推荐)》MySQL是一个流行的关系型数据库管理系统,支持多线程和多种数据库连接途径,能够处理上千万条记录的大型数据库,本文介绍MySql9.1.0安装详细教程,... 目录mysql介绍:一、下载 Mysql 安装文件二、Mysql 安装教程三、环境配置1.右击此电脑