我想将镶木地板文件中的数据帧写入弹性搜索,我想从数据帧的值中创建索引和类型。
我的数据框是
timestamp country data
2017-08-16 00:00:00 india xyz
2017-08-16 00:00:00 US xyz
我有以下代码将此内容写入ES
features.write.format("org.elasticsearch.spark.sql")
.mode(SaveMode.Append)
.option("es.resource","timestamp/country").save()
但这不符合我的预期
这会创建一个索引" timestamp
"和#34; country
"
但是我想创建索引为" 2017-08-16 00:00:00
"和两种类型" india
"和" US
"
答案 0 :(得分:1)
试试
import org.elasticsearch.spark.rdd.EsSpark
使用saveToEs
方法。有关详细信息,请refer
val game = Map("type"->"game","title" -> "FF VI","year" -> "1994")
val book = Map("type" -> "book","title" -> "Harry Potter","year" -> "2010")
val cd = Map("type" -> "music","title" -> "Surfing With The Alien")
sc.makeRDD(Seq(game, book, cd)).saveToEs("index/{type}")