【发布时间】:2016-02-05 17:37:36
【问题描述】:
我正在尝试确定一个程序/软件,它可以让我有效地获取大量大型 CSV 文件(总计 40+ GB)并输出具有我需要导入 Elasticsearch (ES) 的特定格式的 JSON 文件.
jq 可以像这样高效地获取数据吗:
file1:
id,age,gender,wave
1,49,M,1
2,72,F,0
file2:
id,time,event1
1,4/20/2095,V39
1,4/21/2095,T21
2,5/17/2094,V39
按 id 聚合它(这样多个文件中 CSV 行中的所有 JSON 文档都属于一个 id 条目),输出如下内容:
{"index":{"_index":"forum_mat","_type":"subject","_id":"1"}}
{"id":"1","file1":[{"filen":"file1","id":"1","age":"49","gender":"M","wave":"1"}],"file2":[{"filen":"file2","id":"1","time":"4/20/2095","event1":"V39"},{"filen":"file2","id":"1","time":"4/21/2095","event1":"T21"}]}
{"index":{"_index":"forum_mat","_type":"subject","_id":"2"}}
{"id":"2","file1":[{"filen":"file1","id":"2","age":"72","gender":"F","wave":"0"}],"file2":[{"filen":"file2","id":"2","time":"5/17/2094","event1":"V39"}]}
我在 Matlab 中编写了一个脚本,但我担心它会很慢。我可能需要几个月的时间来处理所有 40+GB 的数据。我是informed,Logstash(这是 ES 的首选数据输入工具)不擅长这种类型的聚合。
【问题讨论】:
-
首先将这些数据输入到关系数据库中可能会更容易,经过适当的结构、引用和索引(例如:tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql)然后编写一个返回 json 的查询(例如 dev.mysql.com/doc/refman/5.7/en/json.html)跨度>
-
我最终使用了这种方法,并在下面发布了详细答案。
标签: json matlab csv elasticsearch jq