简体   繁体   中英

Import/Export data in Elastic Search

I have access to an Elastic Search database but I do not have admin permission which enables me to backup data. I just can query. How to transfer all data stored in server to another server? there are millions of records. I think it can be good to export all data to csv and then download data. is there a better way? If cdv is the best approach, how to restore data? I've exported my records this way:

body = {"query": {match_all": {}}}"


res = es.search(index="mydb", doc_type='entry', body=body)

import csv

with open('static/data/sitemap/data.csv', 'wb') as f:  # Just use 'w' mode in 3.x
    w = csv.DictWriter(f, res.keys())
    w.writeheader()
    w.writerow(res)

There are a number of open-source projects that you can use to extract all data from your cluster -- your approach of doing a match_all won't work correctly.

Here are a few open source projects:

And if none of those work for you, you can build your own based on the Scan and Scroll API for ES. According to ES's documentation, the python client is supposed to have support for the scan and scroll API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM