elasticsearch 重建索引 使用python迁移索引数据 reindex

本文介绍了如何使用Elasticsearch进行索引重建和数据迁移。首先,通过curl命令从json文件创建新索引。接着,设置索引别名,将别名从旧索引切换到新索引,实现数据迁移。最后,删除旧索引,确保新索引已替代旧索引并承载所有数据。

1. 首先根据json文档重建索引:

   curl -XPUT 'http://127.0.0.1:9200/index_name/' -d @resume-10-14.json


2. 索引重定向

索引别名:resume_test_alias
旧索引:resume_test_4
新索引:resume_test_5

curl -XPOST http://127.0.0.1:9200/_aliases -d '

{

    "actions": [

        { "remove": {

            "alias":"resume_test_alias",

            "index":"resume_test_4"

        }},

        { "add": {

            "alias":"resume_test_alias",

            "index":"resume_test_5"

        }}

    ]

}’


3. 索引数据迁移——从旧索引迁移到新索引

from elasticsearch import helpers
from elasticsearch import Elasticsearch

es = Elasticsearch([{"host":"127.0.0.1","port":"9200"}])
body={"query":{"match_all":{}}}  #遍历原索引,可自定义query

helpers.reindex(client=es,source_index='resume_test_4',target_index='resume_test_5',target_client=es,query=body,chunk_size=1000, scroll='15m') #重建索引

4. 删除旧索引

curl -XDELETE 101.201.48.85:9200/resume_test_4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值