Elasticsearch索引重建(Rebuild)
2014-08-11 13:09
399 查看
索引重建(Rebuild)
索引创建后,你可以在索引当中添加新的类型,在类型中添加新的字段。但是如果想修改已存在字段的属性(修改分词器、类型等),目前ES是做不到的。如果确实存在类似这样的需求,只能通过重建索引的方式来实现。但想要重建索引,请保证索引_source属性值为true,即存储原始数据。索引重建的过程就是将原来索引数据查询回来入到新建的索引当中去,为了重建过程不影响客户端查询,创建索引时请使用索引别名,例如现在需要将index1进行重建生成index2,index1给客户端提供的别名为index1_alias,完整步骤如下:1、 创建索引索引index1,使用index1_alias作为别名指定。
curl –XPUT localhost:9200/index1 –d‘{ “aliases”:{ “index1_alias”:{} } }’
2、 根据新配置创建索引index2
例如:curl–XPUT localhost:9200/index2 –d ‘{ “settings”:{ “index_number_of_shards”:10 } }’
3、 将旧索引数据导入到新索引中
将索引index1中的数据导入到index2当中,可以将index1原始数据划范围导入到index2中。为了提高查询性能,查询类型选择scan方式。例如:部分1:
GET/ old_index / _search ? search_type = scan & scroll = 1m { "query": { "range": { "date": { "gte":"2014-01-01", "lt":"2014-02-01" } } }, "size": 1000 }
部分2:
GET/ old_index / _search ? search_type = scan & scroll = 1m { "query": { "range": { "date": { "gte": "2014-02-01", "lt": "2014-03-01" } } }, "size": 1000 }
使用上述方式查询原始数据,然后调用ES批量bulk接口索引文档。
4、 索引切换
为了保证系统不停机的情况下进行索引切换,通过修改别名的方式进行修改,即删除index1别名index1_alias,给index2增加index1_alias别名,具体如下:curl –XPUT localhost:9200/_alias ‘{ “action”:[ “remove:{ “index”:”index1”, “alias”:”index1_aias” }”, “add:{ “index”:”index2”, “alias”:”index1_aias” }” ] }’
5、 删除旧索引
curl–XDELETE localhost:9200/index2
相关文章推荐
- Elasticsearch索引重建(Rebuild)
- elasticsearch 索引重建(Rebuild)
- [转载]Elasticsearch索引重建(Rebuild)
- ElasticsearchCRUD使用(七)【Elasticsearch中的实时重建索引】
- MSSQL Rebuild(重建)索引
- elasticsearch 重建索引 使用python迁移索引数据 reindex
- MSSQL Rebuild(重建)索引
- ELK学习总结(4-1)elasticsearch更改mapping(不停服务重建索引)
- elasticsearch以scroll方式 大数据重建索引
- 重建索引:ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILD
- SQL Server 重建索引 Rebuild Index
- 重建索引:ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILD
- elasticsearch更改mapping(不停服务重建索引)
- MSSQL Rebuild(重建)索引
- elasticsearch核心知识---51.基于scroll+bulk+索引别名实现零停机重建索引
- elasticsearch更改mapping,不停服务重建索引(转)
- SQL Server 重建索引 Rebuild Index
- Scipts:生成重建索引的SQL脚本dba_rebuild_indexes.sql
- ES索引重建--使用python elasticsearch
- Scripts:重建索引的脚本(看懂脚本再用)rebuild_indx.sql