Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to save a json file in elasticsearch using spark scala ?

Highlighted

How to save a json file in elasticsearch using spark scala ?

Explorer

I am trying to save a json file in Elasticsearch using spark scala, but the code not working.

here is the code:

import org.apache.spark
import org.apache.spark.{SparkConf, SparkContext}
import org.elasticsearch.spark._
import org.apache.spark.sql._

object JsontoES {
  def main(args: Array[String]): Unit = {



    val conf = new SparkConf().setAppName("HelloWorld").setMaster("local")
    val sc = new SparkContext(conf)
    conf.set("es.index.auto.create", "true")
    val spark = SparkSession
      .builder()
      .appName("Spark SQL basic example")
      .config("spark.some.config.option", "some-value")
      .getOrCreate()
    val jsonpath = "/home/aymenstien/Bureau/mydoc/Orange.json"
    //val ds= spark.read.json(jsonpath)
    sc.esJsonRDD(jsonpath)
    val RDD = sc.esRDD("radio/artists")

    //rddds.saveToEs("jsontoes/json-trips")
   //sc.makeRDD(Seq(ds)).saveToEs("jsontoEs/docs")

  }

}
<br>
Don't have an account?
Coming from Hortonworks? Activate your account here