我需要将大量的 Elasticsearch 索引以 JSON 格式导出到 S3,其中每个索引的大小约为 50GB。我一直在研究多种方法,但由于数据量大,我需要最省时的方法。
我试过 elasticdump,但通过测试,我认为它将整个索引存储在内存中,然后再将其作为文件转储到 S3。所以我需要一个内存超过 50G 的 EC2 实例。有没有办法让它转储一系列较小的文件而不是一个大文件?
还有其他选项,例如使用 Logstash 或 python 的 Elasticsearch 库以及可能的助手来执行操作。
最好的方法是什么?
要将原始
json
从 Elasticsearch 移动到 S3 存储桶,您可以在 logstash 管道中使用 s3 输出。这是要遵循的示例管道
input {
elasticsearch {
hosts => ["localhost:9200"]
index => "myindex-*"
query => '{ "query": { "match_all": {} } }'
}
}
filter {
# Your filter configuration here
}
output {
s3 {
bucket => "BUCKET_NAME"
region => "us-east-1"
access_key_id => "ACCESS_KEY"
secret_access_key => "SECRET_KEY"
canned_acl => "private"
prefix => "logs/" # Optional
time_file => 300
codec => json_lines {}
codec => plain {
format => "%{[message]}"
}
}
}
S3 输出插件 - 参数
time_file => 300
5 分钟(5 分钟 * 60 秒/分钟 = 300 秒)。json_lines
对 JSON 数据进行编码,并将数据格式化为字符串。如果您在 ECS 容器或 EC2 中运行此管道,则无需提供
ACCESS_KEY
和 SECRET_KEY
,出于安全原因,您可以创建角色并分配给 ECS 或 EC2。