代码之家  ›  专栏  ›  技术社区  ›  hard coder

如何使用动态索引和类型将拼花文件写入弹性搜索

  •  0
  • hard coder  · 技术社区  · 7 年前

    我的数据帧是

    timestamp                country    data
    2017-08-16 00:00:00      india      xyz
    2017-08-16 00:00:00      US         xyz
    

    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 "

    1 回复  |  直到 7 年前
        1
  •  1
  •   FaigB    7 年前

    测试

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