使用spark scala在solr中摄取数据

使用spark scala在solr中摄取数据,scala,hadoop,apache-spark,solr,Scala,Hadoop,Apache Spark,Solr,我试图使用scala和spark将数据摄取到solr,但是,我的代码缺少了一些东西。例如,我从Hortonworks教程中获得了以下代码。 我使用的是spark 1.6.2、solr 5.2.1和scala 2.10.5 有谁能给我提供一个可行的代码片段来成功地将数据插入solr吗 val input_file = "hdfs:///tmp/your_text_file" case class Person(id: Int, name: String) val people_df1

我试图使用scala和spark将数据摄取到solr,但是,我的代码缺少了一些东西。例如,我从Hortonworks教程中获得了以下代码。 我使用的是spark 1.6.2、solr 5.2.1和scala 2.10.5

有谁能给我提供一个可行的代码片段来成功地将数据插入solr吗

val input_file = "hdfs:///tmp/your_text_file"
   case class Person(id: Int, name: String)
   val people_df1 = sc.textFile(input_file).map(_.split(",")).map(p => Person(p(0).trim.toInt, p(1))).toDF()
   val docs = people_df1.map{doc=>
     val docx=SolrSupport.autoMapToSolrInputDoc(doc.getAs[Int]("id").toString, doc, null)
     docx.setField("scala_s", "supercool")
     docx.setField("name_s", doc.getAs[String]("name"))

   }
//下面的代码在某种程度上存在编译问题,尽管jar文件不包含这些函数

SolrSupport.indexDocs("sandbox.hortonworks.com:2181","testsparksolr",10,docs)
       val solrServer = com.lucidworks.spark.SolrSupport.getSolrServer("http://ambari.asiacell.com:2181")
       solrServer.setDefaultCollection("
testsparksolr")
   solrServer.commit(false, false)
提前谢谢

您试过了吗

该库的主要重点是提供一个干净的API,将文档索引到Solr服务器,就像您的情况一样