虚拟化容器,大数据,DBA,中间件,监控。

elasticsearch7 安装中文分词器与使用方法

16 03月
作者:admin|分类:大数据

elasticsearch7 安装中文分词器与使用方法


发车

    为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了,因此我们需要一个中文分词器来用于搜索和使用。今天我们就尝试安装下IK分词。

上车

1、去github 下载对应的分词插件
https://github.com/medcl/elasticsearch-analysis-ik/releases
根据不同版本下载不同的分词插件

2、到es的plugins 目录创建文件夹
cd your-es-root/plugins/ && mkdir ik

3、解压ik分词插件到ik文件夹

unzip elasticsearch-analysis-ik-6.4.3.zip

第二种安装方法

还有一种方式 直接通过es的命令进行安装,根据自己的ES版本靠近可用的ik分词器版本

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip

或是

.//bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.2/elasticsearch-analysis-ik-7.10.2.zip


也可以将ik.zip文件直接下载后,再到elasticsearch/plugins/中新建个analysis-ik目录,再将zip文件解压到里面。


安装好后 重启es
会看到 加载了 ik分词了

到站

IK 分词器简介

  • 1,Elasticsearch中文分词我们采用Ik分词,ik有两种分词模式,ik_max_word,和ik_smart模式;

    • ik_max_word 和 ik_smart 什么区别?

ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;
ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。

索引时,为了提供索引的覆盖范围,通常会采用ik_max_word分析器,会以最细粒度分词索引,搜索时为了提高搜索准确度,会采用ik_smart分析器,会以粗粒度分词

实测

创建index

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

创建 mapping

curl -XPOST http://localhost:9200/index/index_mapping -H 'Content-Type:application/json' -d' {

"properties": {

"content": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_smart"

}

}

}'



添加几个数据


curl -XPOST http://localhost:9200/index/index/1 -H 'Content-Type:application/json' -d'  {"content":"美国留给伊拉克的是个烂摊子吗"}  '


curl -XPOST http://localhost:9200/index/index/3 -H 'Content-Type:application/json' -d'  {"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}  '


curl -XPOST http://localhost:9200/index/index/4 -H 'Content-Type:application/json' -d'  {"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}  '



进行查询


curl -XPOST http://localhost:9200/index/index/_search -H 'Content-Type:application/json' -d'  

{

"query": {

"match": {

"content": "中国"

}

},

"highlight": {

"pre_tags": ["<tag1>", "<tag2>"],

"post_tags": ["</tag1>", "</tag2>"],

"fields": {

"content": {}

}

}

}


查看效果



浏览695 评论0
返回
目录
返回
首页
Elasticsearch7.2集群的安全性配置 Oracle 关于 not in 的坑 ,not in 查询不出数据