這篇文章主要介紹“怎么通過spark將數(shù)據(jù)存儲到elasticsearch”,在日常操作中,相信很多人在怎么通過spark將數(shù)據(jù)存儲到elasticsearch問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么通過spark將數(shù)據(jù)存儲到elasticsearch”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

maven依賴
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-spark-20_2.11</artifactId>
<version>6.6.0</version>
</dependency>
package hgs.spark.es
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.elasticsearch.spark._
import org.apache.spark.sql.SQLContext
object ViaSparkLoadDataToES {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("toEs").setMaster("local")
conf.set("es.resource", "mtest/IT")
conf.set("es.nodes", "bigdata00,bigdata01")
conf.set("es.port", "9200")
val context = new SparkContext(conf)
val sqlContext = new SQLContext(context)
import sqlContext.implicits._
val rdd = context.textFile( "d:\\person",1)
//val jsonrddDF = sqlContext.read.json(rdd)
rdd.saveJsonToEs("mtest/IT")
context.stop()
}
}到此,關(guān)于“怎么通過spark將數(shù)據(jù)存儲到elasticsearch”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
標(biāo)題名稱:怎么通過spark將數(shù)據(jù)存儲到elasticsearch-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://www.chinadenli.net/article30/dcsoso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、營銷型網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)、動態(tài)網(wǎng)站、自適應(yīng)網(wǎng)站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容