我正在尝试使用带有 spark-1.3.1 的 elasticsearch-spark-2.1.0 对 elasticsearch 中的数据进行索引,但出现以下错误:
org.elasticsearch.hadoop.serialization.EsHadoopSerializationException: Cannot handle type [class scala.collection.immutable.Map$Map3] within type [class scala.collection.immutable.Map$Map4], instance [Map(word -> ..., pos -> ...)] within instance [Map(page_title -> ..., full -> ..., tokens -> [Lscala.collection.immutable.Map;@1efb3e9)] using writer [org.elasticsearch.spark.serialization.ScalaValueWriter@200c86fd]
这是我索引火花 RDD 的代码。
val spark = new SparkContext(...)
val filesRDD = spark.wholeTextFiles("hdfs://" + source_dir + "/*", 200)
// val sentenceList: RDD[Map[String, Object with Serializable { .. }]]
val sentenceList = filesRDD.flatMap(file => ...)
.flatMap { page =>
page.sentences.map { sentence =>
Map("page_title" -> page.title,
"full" -> sentence.map(_.word).mkString(" "),
"tokens" -> sentence.map { t =>
Map("word" -> t.word, "pos" -> t.pos)
}.toArray)
}
}
EsSpark.saveToEs(sentenceList, ES_RESOURCE)
为什么我不能在地图中索引地图,我该如何解决?谢谢。