scala - 使用 spark scala 在 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 = 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)

提前致谢

最佳答案

你试过了吗spark-solr

库的主要重点是提供一个干净的 API 来将文档索引到您的情况下的 Solr 服务器。

关于scala - 使用 spark scala 在 solr 中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43830900/

相关文章:

scala - 无法在本地主机中使用 Solr 连接到 ZooKeeper

json - 如何将行合并到 Spark 数据框的列中作为有效的json以将其写入mysql

scala - Spark 数与拍摄和长度

git - 带有 Git : How should the . gitignore 的 IntelliJ 上的 Scala 看起来像什么?

scala - Spark 数据框将列值获取到字符串变量中

scala - 自动装箱是否比自定义包装器类型表现更好?

hadoop - Reducer个数的逻辑

hadoop - HDFS 中参数 "mapred.min.split.size"的行为

hadoop - 在Zeppelin中使用SparkSQL查询Hive表时,为什么会收到此IO异常?

scala - 在 spark DataFrame- Scala 中格式化 TimestampType