ElasticSearch to Spark RDD

旧时模样 提交于 2019-12-03 07:16:42

You should use the following codes to initialize:

val sparkConf = new SparkConf().setAppName("Test").setMaster("local").set("spark.serializer", classOf[KryoSerializer].getName)
val sc = new SparkContext(sparkConf)
val conf = new JobConf()
conf.set("es.nodes", "localhost:9200")
conf.set("es.resource", "bank/account")
conf.set("es.query", "?q=firstname:Daniel")

you can try

val spark = new SparkConf()
    .set("spark.serializer","org.apache.spark.serializer.KryoSerializer")
    .set("es.nodes",localhost)
    .set("es.port","9200")
    .appName("ES")
    .master("local[*]")


val data = spark.read
  .format("org.elasticsearch.spark.sql")
  .option("es.query", "?q=firstname:Daniel")") 
  .load("bank/account").rdd

data.first()
data.collect()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!