1. 程式人生 > >elasticsearch 重建索引 使用python遷移索引資料 reindex

elasticsearch 重建索引 使用python遷移索引資料 reindex

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