版本:
spark:2.3.0
elasticsearch:6.2.3
依赖:
<dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch-spark-20_2.11</artifactId> <version>6.2.4</version> </dependency>
将dataframe写入es代码:
package forms import org.apache.spark.sql.{DataFrame, SparkSession} import org.elasticsearch.spark.sql.EsSparkSQL object Form_3 { val sparkSession = SparkSession.builder() .config("es.index.auto.create", "true") .config("es.nodes", "192.168.2.246") .master("local[*]").appName("").getOrCreate() def main(args: Array[String]): Unit = { val all_df = sparkSession.read.parquet("/UZ/Taobao/search_list/*/*/*/*","/UZ/Tmall/search_list/*/*/*/*") EsSparkSQL.saveToEs(all_df,"good/info") } }