使用Spark Streaming问题保存在Elasticsearch中

时间:2015-12-31 11:59:38

标签: twitter elasticsearch spark-streaming

我正在尝试使用Spark Streaming保存在Elasticsearch中。代码可以工作,但只有在我停止进程后才能保存到弹性搜索(我从intelliJ IDEA启动它)。 只要他们进入流媒体,我就需要保存twitts。

谢谢!

这是我的代码:

tweets.foreachRDD(tweet => {
  if (tweet.isEmpty) {
    println("no se han recibido tweets en este tramo de tiempo")
  } else {
    val tweetsRdd = tweet.map(t => {
      System.out.println(t.getText)
      var country = ""
      if (t.getPlace() != null) {
        country = t.getPlace().getCountry()
      }
      val hashtag = t.getText().split(" ").filter(word => word.startsWith("#"))
      Tweet(t.getUser().getName(), t.getUser().getLang(), t.getText(), t.getCreatedAt(), t.getRetweetCount(), country, t.isRetweet(), t.getUser().getFollowersCount(), hashtag)

    })
    EsSpark.saveToEs(tweetsRdd, index_name + "/" + type_name)

  }
}
)

ssc.start()
ssc.awaitTermination()

0 个答案:

没有答案