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