我试图使用Apache在弹性搜索中创建一个索引(将海量数据写入ES),.I已经完成了一个Scala程序来使用ApacheS以来创建索引,我不得不索引巨大的数据,这是作为我的产品bean在一个LinkedList中得到的。Then.Then我尝试遍历产品bean列表并创建索引。下面是我的代码。
val conf = new SparkConf().setAppName("ESIndex").setMaster("local[*]")
conf.set("es.index.auto.create", "true").set("es.nodes", "127.0.0.1")
.set("es.port", "9200")
.set("es.http.timeout", "5m")
.set("es.scroll.size", "100")
val sc = new SparkContext(conf)
//Return my product bean as a in a linkedList.
val list: util.LinkedList[product] = getData()
for (item <- list) {
sc.makeRDD(Seq(item)).saveToEs("my_core/json")
}这种方法的问题在于创建索引花费了太多的时间。有没有更好的方法来创建索引?
发布于 2016-03-09 10:24:39
getData返回的数据源的不同,您应该使用相关的输入方法或创建自己的输入方法。如果数据来自MongoDB,例如使用mongo-hadoop、Spark-MongoDB或钻取JDBC连接。然后使用map或类似的方法来构建所需的对象,并在转换的RDD上使用saveToEs。https://stackoverflow.com/questions/35887978
复制相似问题