如何使用动态索引和类型将镶木地板文件写入弹性搜索

How to write parquet files to elastic search with dynamic index and type

我想将镶木地板文件中的数据帧写入弹性搜索,并且我想动态地从数据帧的值创建索引和类型。

我的数据框是

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”和一个类型“country

但是我想创建索引为“2017-08-16 00:00:00”和两种类型“india”和“US

试用

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}")