import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}
import org.elasticsearch.spark.sql._
object ESDemoSqlConfigOptionSql {
def main(args: Array[String]):Unit = {
val spark = SparkSession.builder()
.appName("ESDemoSqlConfigOptionSql")
.getOrCreate()
val options =Map(
"es.index.auto.create" ->"false",
"es.nodes.wan.only" ->"false",
"es.nodes" ->"127.0.0.1:9200",
"es.net.http.user" ->"user",
"es.net.http.auth.pass" ->"pwd",
"es.mapping.id" ->"rowkey",
"es.resource" ->"targettb1/_doc"
)
val df1:DataFrame = spark.sql("select * from targettb1")
df1.saveToEs(options)
df1.write
.options(options)
.mode(SaveMode.Append)
.format("org.elasticsearch.spark.sql.DefaultSource15")
.save()
}
}