rancher2.X笔记(十三):k8s环境下安装中文分词插件

  1. 共享es文件夹

主节点操作

mkdir es
mkdir es/plugins
# 加入这行
sudo vi /etc/exports
/home/shenyi/es    192.168.0.0/24(rw,async,insecure,no_root_squash)
# 重新加载配置
exportfs -r

子节点操作

mkdir es
mkdir es/plugins
# 挂载
sudo mount -t nfs 192.168.0.211:/home/shenyi/es   /home/shenyi/es
  1. 下载插件

下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.4.2

注意:分词器必须和你的ES版本一致,必须、必须、必须

下载完上传到~/es/plugins里,文件夹名为analysis-ik

  1. 创建PV

rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
4. 创建PVC
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
5. 服务挂载PVC
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
rancher2.X笔记(十三):k8s环境下安装中文分词插件
挂载

/usr/share/elasticsearch/plugins

重启服务(es服务和kb服务)
rancher2.X笔记(十三):k8s环境下安装中文分词插件
6. 测试
rancher2.X笔记(十三):k8s环境下安装中文分词插件

// 创建索引
PUT /books
{
  "mappings": {
    "properties": {
      "BookID":    { "type": "integer" },
      "BookName":    { "type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart","fields":{ "keyword":{"type":"keyword","ignore_above":256}}},  
      "BookPrice":   { "type": "float"},  
      "BookAuthor":   { "type": "keyword"}
    }
  }
}
// 批量插入一些数据
POST _bulk
{ "index" : { "_index" : "books", "_id" : "101" } }
{"BookID":101,"BookName":"C语言程序设计","BookPrice":19,"BookAuthor":"老蒋"}
{ "index" : { "_index" : "books", "_id" : "102" } }
 {"BookID":102,"BookName":"PHP高级编程","BookPrice":29,"BookAuthor":"老李"}
{ "index" : { "_index" : "books", "_id" : "103" } }
 {"BookID":103,"BookName":"java编程从入门到精通","BookPrice":39,"BookAuthor":"老王"}
{ "index" : { "_index" : "books", "_id" : "104" } }
 {"BookID":104,"BookName":"无需流汗和吃苦3天成为java大神","BookPrice":15.5,"BookAuthor":"老张"}
// 用sql语句查询
POST /_sql
{  
   "query": "SELECT * FROM books WHERE BookAuthor = '老王'"
}

 POST /_sql
{  
   "query": "SELECT BookName,BookID FROM books WHERE match(BookName,'我从小就喜欢编程')"
}

POST /_sql
{  
   "query": "SELECT BookName,BookID FROM books WHERE match('BookName','我从小就喜欢java编程') order by SCORE() desc "
}
上一篇:最长公共子序列(DP)


下一篇: 图书管理前端页面