现在我想把几十 G 的信息从 elasticsearch 迁移到 hadoop. 用的方式是 spark + elasticsearch-hadoop
Demo 代码如下:
$ ./bin/pyspark --driver-class-path=/path/to/elasticsearch-hadoop.jar
>>> conf = {"es.resource" : "index/type"} # assume Elasticsearch is running on localhost defaults
>>> rdd = sc.newAPIHadoopRDD("org.elasticsearch.hadoop.mr.EsInputFormat",\
"org.apache.hadoop.io.NullWritable", "org.elasticsearch.hadoop.mr.LinkedMapWritable", conf=conf)
>>> rdd.first() # the result is a MapWritable that is converted to a Python dict
(u'Elasticsearch ID',
{u'field1': True,
u'field2': u'Some Text',
u'field3': 12345})
按照这种方式能够正常地从 es 迁移数据,但是现在有一个问题,就是迁移的速度太慢了.
我想出了一个解决方案如下:
首先我通过日期创建 n 个迁移的任务,然后让他们同时在 spark 集群上执行,然后集群上的 core 数只够 k 个任务,那么就让(n-k)个任务自己在排队等待资源
有没有更好的解决方案呢?