Elasticsearch如何更新mapping
来源:互联网 发布:chm生成软件 编辑:程序博客网 时间:2024/06/05 17:39
Elasticsearch 的 mapping 在创建
indices
时即已确定,无法更改。那么,当我们需要更新 mapping 时,该如何是好呢?
基本思路
当我们在创建一条索引时,添加好 mapping 后,可设置一个
alias
指向该索引,然后生产环境采用该alias
来索引数据。当然,如果没有这样做的话,建议趁早备份,修改 API 。
既然已创建的 indices 无法修改,我们可以重新创建一个新的 indices
, 然后将原 indices 上的数据复制到新的 indices 上,再将 alias
指向新 indices
。最后,删除原索引。
参数说明
- 当前索引名称:
test_v1
- 生产索引名称:
test
- 目标索引名称:
test_v2
操作步骤
将生产索引指向当前索引:
test
->test_v1
- Method: POST
- Url: http://localhost:9200/_aliases
Body:
{ "actions": [ { "add" : { "index" : "test_v1", "alias" : "test" } } ]}
创建新索引
test_v2
- Method: PUT
- Url: http://localhost:9200/test_v2
Body:
{ "mappings": { "content": { "properties": { "title": { "type": "text", "fields": { "accurate": { "type": "keyword" } }, "analyzer": "ik_smart", "search_analyzer": "ik_smart", "include_in_all": "true" }, "content": { "type": "text", "analyzer": "ik_smart", "search_analyzer": "ik_smart", "include_in_all": "true" }, "author": { "type": "keyword" }, "category": { "type": "keyword" } } } }}
复制数据:
test_v1
->test_v2
- Method: POST
- Url: http://localhost:9200/_reindex
Body:
{ "source": { "index": "test_v1" }, "dest": { "index": "test_v2" }}
修改别名:
test
->test_v2
- Method: POST
- Url: http://localhost:9200/_aliases
Body:
{ "actions": [ { "remove" : { "index" : "test_v1", "alias" : "test" } }, { "add" : { "index" : "test_v2", "alias" : "test" } } ]}
- 删除旧索引:
test_v1
- Method: DELETE
- Url: http://localhost:9200/test_v1
小结
至此,我们达到了伪更新的效果。不过这里存在一个问题,如果数据量超大的话,复制数据所消费的时间比较多,所以请在构建索引前尽量考虑周全。
阅读全文
0 0
- Elasticsearch如何更新mapping
- Elasticsearch如何设置mapping
- elasticsearch中更新mapping的方式
- elasticsearch mapping
- elasticsearch mapping
- elasticsearch mapping
- elasticsearch mapping
- elasticsearch mapping
- elasticsearch mapping
- elasticsearch中的mapping简介
- elasticsearch 修改 mapping
- Elasticsearch mapping配置文件格式
- elasticsearch之mapping field
- elasticsearch之mapping types
- elasticsearch中的mapping简介
- elasticsearch-mapping-introduction
- Elasticsearch:Mapping篇
- elasticsearch mapping 学习
- android两种序列化方式
- SpringMVC 中Model、ModelMap和ModelAndView的区别和用法
- Android -Bundle类
- VC中实现弹出CEdit的气泡提示框
- SVM手写数字图像分类
- Elasticsearch如何更新mapping
- 神经网络识别字母+数字
- 第2章 InnoDB存储引擎
- Android音频驱动-ASOC之Machine
- opencv配置问题:由于找不到MSVR120D.dll程序无法继续执行
- Array对象的方法实现(1)----Array.prototype.push和Array.prototype.concat(实现常规参数的功能)
- LeetCode 236. Lowest Common Ancestor of a Binary Tree
- 常见的加密方式!
- C++——USACO Section 3.1 题解