项目中经常出现的问题,例如添加字段、修改字段,那原先的索引规则就要跟着改变,最好是一开始就给索引一个别名,修改字段时新增映射,然后将笔名指向新的映射,当然需要将之前的索引搬迁到新的映射当中。

1、获取映射信息(例如索引库是db_student)

GET  http://localhost:/db_student/_mapping

这时可以看到返回结果:

{
"db_student": {
"mappings": {
"properties": {
"chinese": {
"type": "integer",
"store": true
},
"class": {
"type": "integer",
"store": true
},
"english": {
"type": "integer",
"store": true
},
"math": {
"type": "integer",
"store": true
},
"name": {
"type": "text",
"store": true
},
"school": {
"type": "text",
"store": true,
"analyzer": "ik_max_word"
}
}
}
}
}

这正是上一篇我们设置的映射规则,现在我们想要增加一列 desc ,用来保存学生的自我介绍介绍信息,首先,我们可以为 索引库 db_student 取一个别名  student 。

2、为旧索引库   db_student  起一个别名  student

PUT   http://localhost:/db_student/_alias/student

此时,再查一下就索引库有哪些别名:

GET  http://localhost:/db_student/_alias

呈现的效果是:

{
"db_student": {
"aliases": {
"student": {}
}
}
}

此时,别名已经生效。

3、建立新的索引库  db_student_v1,在原索引库的基础上加上 desc 这一新的字段,并且使用 ik 分词

PUT  http://localhost:/db_student_v1
{
"mappings": {
"properties": {
"class": {
"type": "integer",
"store": true,
"index":true
},
"chinese": {
"type": "integer",
"store": true,
"index":true
},
"english": {
"type": "integer",
"store": true,
"index":true
},
"math": {
"type": "integer",
"store": true,
"index":true
},
"name": {
"type": "text",
"store": true,
"index":true
},
"school": {
"type": "text",
"store": true,
"index":true,
"analyzer":"ik_max_word"
},
"desc": {
"type": "text",
"store": true,
"index":true,
"analyzer":"ik_max_word"
}
}
}
}

4、数据搬迁,现在将索引库 db_student  的数据搬到新的索引库  db_student_v1

POST  http://localhost:/_reindex
{
"conflicts": "proceed",
"source": {
"index": "db_student"
},
"dest": {
"index": "db_student_v1",
"op_type": "create",
"version_type": "external"
}
}

5、更改别名,将旧版索引库 db_student 的别名去除,将别名指向新版的索引库 db_student_v1

去除旧版索引库 db_student 的别名:

POST  http://localhost:/_aliases
{
"actions": [
{
"remove": {
"index": "db_student",
"alias": "student"
}
}
]
}

为新版索引库 db_student_v1 加上别名:

POST  http://localhost:/_aliases
{
"actions": [
{ "add": {
"index": "db_student_v1",
"alias": "student"
}
}
]
}

此时就可以统一按照别名 student 来进行上一篇的所有查询动作。

最新文章

  1. Mac OS 下 mysql 找不到 mysql.sock 的问题
  2. css属性在各种浏览器上的兼容性
  3. SQL Server存储过程多角度介绍
  4. Windows 上的 Jetty 小工具
  5. iOS - OC NSStream 文件流
  6. msf命令全集
  7. $key 的用法
  8. Linux 性能监控的18个命令行工具
  9. AVR抗干扰能力一般
  10. A Guide to the Multiboot Process
  11. hdu3306 Another kind of Fibonacci【矩阵快速幂】
  12. 前端project师,确定你的目标吧!无能的人才管他叫命运
  13. JAVA判断32位还是64位,调用不同的DLL(转)
  14. MongoDB数据库文档操作
  15. Tomcat 笔记-配置虚拟目录
  16. log4donet 的 一篇简单使用实例
  17. HttpUtility.UrlEncode()关于空格的编码问题
  18. vue刷新路由,不刷新页面
  19. Docker 系列七(Dubbo 微服务部署实践).
  20. ARGB与RGB、RGBA的区别

热门文章

  1. 网络编程-UDP、TCP
  2. Kafka 是如何管理消费位点的?
  3. JavaScript动画实例:旋转的正三角形
  4. Ethical Hacking - NETWORK PENETRATION TESTING(2)
  5. 服务端socket重用属性设置
  6. 高效C++:设计与声明
  7. ThreadLocal 原理
  8. Spring Security系列之极速入门与实践教程
  9. Arch Linux, 无法启动进入sddm登录
  10. Python删除元组