当前位置: 首页 > news >正文

elasticsearch安装分词器和操作

安装分词器

1,查看分词器是否安装
# 检查已安装的插件
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin list

如果没有安装,进行安装,此方法安装的时候提示分词器不存在

2,安装分词器
方法一:直接下载安装
# 如果 IK 分词器未安装,安装它
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.0/elasticsearch-analysis-ik-7.10.0.zip

用这种方法试试

# 创建临时目录
mkdir -p /tmp/ik_plugin
cd /tmp/ik_plugin# 下载 IK 分词器(使用备用链接)
wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-ik/elasticsearch-analysis-ik-7.10.0.zip# 如果上面的链接不行,尝试从其他源下载
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.0/elasticsearch-analysis-ik-7.10.0.zip

如果还提示404不存在

方法二:从源码编译安装

在码云上搜索elasticsearch-analysis-ik这个
打开连接搜索的链接Gitee根据自己的版本进行下载,我这里下载的是7.10版本
在这里插入图片描述
下载完之后解压

#解压
sudo unzip elasticsearch-analysis-ik-7.10.zip

如果没有安装maven,进行安装

cd elasticsearch-analysis-ik-7.10/
#安装maven
sudo apt install maven
#停止es
sudo systemctl stop elasticsearch
#编译打包
cd elasticsearch-analysis-ik-7.10/

安装分词器

sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install ./elasticsearch-analysis-ik-7.10/target/releases/elasticsearch-analysis-ik-7.10.0.zip

成功的界面
在这里插入图片描述

备注:这里查看下生成的压缩文件是哪个版本,如果不是elasticsearch-analysis-ik-7.10.0.zip版本,就需要修改pom文件
修改pom文件,如果没有报错,执行执行启动es的那一步

# 回到源码目录
cd /home/jing/Downloads/elasticsearch-analysis-ik-7.10# 修改版本号
nano pom.xml

找到这一行并修改:

<elasticsearch.version>7.10.2</elasticsearch.version>

改为

<elasticsearch.version>7.10.0</elasticsearch.version>

然后重新编译

mvn clean package -DskipTests

再次执行

sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///home/jing/Downloads/elasticsearch-analysis-ik-7.10/target/releases/elasticsearch-analysis-ik-7.10.0.zip

启动es

sudo systemctl start elasticsearch

查看安装的分词器

sudo /usr/share/elasticsearch/bin/elasticsearch-plugin list

显示
在这里插入图片描述

# 测试 IK 分词器
curl -X GET "http://localhost:9200/_analyze" -H 'Content-Type: application/json' -d'
{"analyzer": "ik_smart","text": "中华人民共和国"
}'

es的操作

#删除索引
curl -X DELETE "http://localhost:9200/knowledge"
#查看索引
curl -X GET "http://localhost:9200/knowledge"
#查看映射
curl -X GET "http://localhost:9200/knowledge/_mapping"# 查看索引设置
curl -X GET "http://localhost:9200/knowledge/_settings?pretty"

查看索引中的所有数据

# 查看索引中的所有文档
curl -X GET "http://localhost:9200/knowledge/_search?pretty"# 或者使用 POST 方式
curl -X POST "http://localhost:9200/knowledge/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": {"match_all": {}}
}'
# 查看前5条数据
curl -X GET "http://localhost:9200/knowledge/_search?pretty" -H 'Content-Type: application/json' -d'
{"size": 5,"query": {"match_all": {}}
}'```2. 查看特定文档```bash
# 根据文档ID查看
curl -X GET "http://localhost:9200/knowledge/_doc/1?pretty"# 查看多个文档
curl -X GET "http://localhost:9200/knowledge/_doc/1,2,3?pretty"
  1. 搜索特定内容
# 搜索包含特定关键词的文档
curl -X GET "http://localhost:9200/knowledge/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": {"match": {"fileName": "测试"}}
}'# 多字段搜索
curl -X GET "http://localhost:9200/knowledge/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": {"multi_match": {"query": "测试","fields": ["fileName", "content"]}}
}'

最常用的几个命令:

# 1. 快速查看所有数据
curl -X GET "http://localhost:9200/knowledge/_search?pretty"# 2. 查看文档数量
curl -X GET "http://localhost:9200/knowledge/_count?pretty"# 3. 查看映射结构
curl -X GET "http://localhost:9200/knowledge/_mapping?pretty"# 4. 搜索特定内容
curl -X GET "http://localhost:9200/knowledge/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": {"match": {"fileName": "搜索关键词"}}
}'
http://www.dtcms.com/a/541354.html

相关文章:

  • ubuntu系统安装elasticsearch
  • 网站seo分析常用的工具是华建河北住房和城乡建设厅网站
  • 做网站客户尾款老不给怎么办h5登录页面
  • 黑马JAVA+AI基础11-面向对象编程-常用API-String-ArrayList
  • 平东网站建设引流量的网站
  • 解决Docker容器中出现的错误“Pangolin X11: Failed to open X display”
  • Spring DAO与JDBC优化实战
  • asp access网站架设教程网站如何做即时聊天
  • R 语言科研绘图第 80 期 --- 词云图
  • 通信算法之336 :3GPPMixed Mode Turbo Decoder
  • 如何创建自己的网站店面设计装修网
  • 【软考】信息系统项目管理师
  • WEBSTORM前端 —— 第6章:JavaScript进阶 —— 第2节:构造函数数据常用函数
  • 可以做软件的网站有哪些功能吗现在最火的推广平台有哪些
  • 数字化总架构师:在浪潮中锚定方向,成就组织与自我梦想
  • 网站开发主流语言用文字工具在页面中间输入主标题和副
  • Linux - ab压力测试
  • React 实现 i18next 中英文切换集成
  • 智能无人仓库管理系统(含详细码源~基于React+TypeScript+Vite):
  • 开一家网站建设公司怎样机械设备网站源码
  • 成都网站建设 雷wordpress上传代码
  • 家电维修怎么自己做网站设计官网收费标准
  • HTML 事件
  • 南京网站优化建站芜湖中凡网站建设公司
  • Altium Designer22.0.2-----1:1打印PCB对比实体板
  • 绍兴建设局网站首页wordpress阿里云域名转移
  • 淮南商城网站建设地址wordpress 安装平台
  • 【音视频】DASH 和 SRT协议与传统协议对比
  • 取证考核(10.28)
  • QPSK调制在瑞利、高斯和莱斯信道下的MATLAB仿真