Spark reads and writes data to Elasticsearch

Source: Internet
Author: User

def main (args:array[string]): Unit = {val sparkconf = new sparkconf (). Setappname ("DecisionTree1"). Setmaster ("local[2") ") Sparkconf.set (" Es.index.auto.create "," true ") Sparkconf.set (" Es.nodes "," 10.3.162.202 ") Sparkconf.set (" Es.port  "," 9200 ") val sc = new Sparkcontext (sparkconf)//write2es (SC) read4es (SC); } def write2es (sc:sparkcontext) = {val numbers = Map ("One", 1, "One", "2", "three", 3) Val Airports = Map ("OTP", "Otopeni", "SFO", "San Fran") var Rdd = Sc.makerdd (Seq (numbers, airports)) Esspark.savetoes (R DD, "Spark/docs") println ("--------------------End-----------------")} def read4es (Sc:sparkcontext) {val Rdd = Esspark.esrdd (SC, "Spark/docs") Rdd.foreach (line = {val key = line._1 val value = line._2 println (" ------------------key: "+ key" for (TMP <-value) {val Key1 = tmp._1 val value1 = tmp._2 pri Ntln ("------------------key1:" + key1) println ("------------------value1: "+ value1)}})} 

Example Dependent Jar:elasticsearch-spark_2.10-2.1.0.jar

Spark reads and writes data to Elasticsearch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.