简体   繁体   English

在Elastic Search中导入/导出数据

[英]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. 我可以访问Elastic Search数据库,但没有管理员权限,因此无法备份数据。 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. 我认为将所有数据导出到csv然后下载数据会很好。 is there a better way? 有没有更好的办法? If cdv is the best approach, how to restore data? 如果cdv是最好的方法,如何还原数据? 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. 您可以使用许多开源项目从集群中提取所有数据-您执行match_all将无法正常工作。

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. 而且,如果这些都不适合您,您可以基于适用于ES的Scan and Scroll API构建自己的数据库。 According to ES's documentation, the python client is supposed to have support for the scan and scroll API. 根据ES的文档, python客户端应该支持扫描和滚动API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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