spark读取ES数据

maven pom依赖配置:

 

<dependency>
  <groupId>org.elasticsearchgroupId>
  <artifactId>elasticsearch-spark-13_2.10artifactId>
  <version>6.1.2version>
dependency>

 

code:

 

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

object ReadEs {
  def main(args: Array[String]){

    System.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    System.setProperty("hadoop.home.dir", "C:\\hadoop-2.6.0-cdh5.11.0")
    val conf = new SparkConf().setAppName("READES").setMaster("local").set("es.nodes","172.18.10.34")

    val sc = new SparkContext(conf)


//    val query = """{"query" : { "match" : { "content" : "上海" }}}"""
//    val query = """{"query" : { "match" : { "_id" : 1 }}}"""
//    val RDD = sc.esRDD("tracy/fulltext",query)

   
val RDD = sc.esRDD("tracy/fulltext")

    RDD.collect().foreach(x=> (println(x._1,x._2)))

    sc.stop()

  }

}

 

执行测试:

spark读取ES数据_第1张图片

 

 

你可能感兴趣的:(spark)