Get the App
SLTechnology News&Howtos  ›  Development  › 

How to store data to elasticsearch through spark

Shulou Source: shulou.com Published: 2022-06-03 20:15:36 11月12日 Update

This article mainly introduces "how to store data to elasticsearch through spark". In daily operation, I believe that many people have doubts about how to store data to elasticsearch through spark. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "how to store data to elasticsearch through spark". Next, please follow the editor to study!

Maven relies on org.elasticsearch elasticsearch-spark-20_2.11 6.6.0 package hgs.spark.esimport org.apache.spark.SparkConfimport org.apache.spark.SparkContextimport org.apache.spark.SparkContext._import org.elasticsearch.spark._import org.apache.spark.sql.SQLContextobject 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 ()} so far The study on "how to store data to elasticsearch through spark" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Data storage learning more help practical next articles methods theories knowledge articles websites materials follow questions easy to use practice solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft MariaDB macOS Linux