好的,我正在尝试在我在Kibana的索引中生成地理点以使用 map 。
这是我的代码:
import org.apache.spark.{SparkContext, SparkConf}
import org.elasticsearch.spark._
object KibanaIndice {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("PruebaKibana")
conf.set("es.index.auto.create", "true").set("spark.driver.allowMultipleContexts", "false")
val sc = new SparkContext(conf)
val mapa = Seq(
Map("year" -> "2014-01-11","total" -> 123,"aprobadas"->12,"days"->33,"formalizadas"->8, "loca"-> "41.722, -34.456"),
Map("year" -> "2014-02-11","total" -> 223,"aprobadas"->43,"days"->28,"formalizadas"->22,"loca"-> "42.722, -34.456"),
Map("year" -> "2014-03-11","total" -> 154,"aprobadas"->112,"days"->10,"formalizadas"->26, "loca"-> "43.722, -34.456"),
Map("year" -> "2014-04-11","total" -> 333,"aprobadas"->221,"days"->33,"formalizadas"->100, "loca"-> "44.722, -34.456"),
Map("year" -> "2014-05-11","total" -> 445,"aprobadas"->411,"days"->12,"formalizadas"->343, "loca"-> "45.722, -34.456"),
Map("year" -> "2014-06-11","total" -> 64,"aprobadas"->55,"days"->28,"formalizadas"->36, "loca"-> "46.722, -34.456"),
Map("year" -> "2014-07-11","total" -> 34,"aprobadas"->22,"days"->28,"formalizadas"->16, "loca"-> "47.722, -34.456"),
Map("year" -> "2014-08-11","total" -> 2344,"aprobadas"->2134,"days"->23,"formalizadas"->1322, "loca"-> "48.722, -34.456"),
Map("year" -> "2014-09-11","total" -> 433,"aprobadas"->344,"days"->21,"formalizadas"->256, "loca"-> "49.722, -34.456"),
Map("year" -> "2014-10-11","total" -> 312,"aprobadas"->190,"days"->22,"formalizadas"->26, "loca"-> "50.722, -34.456"),
Map("year" -> "2014-11-11","total" -> 1100,"aprobadas"->900,"days"->21,"formalizadas"->444, "loca"-> "51.722, -34.456"),
Map("year" -> "2014-12-11","total" -> 234,"aprobadas"->201,"days"->21,"formalizadas"->144, "loca"-> "52.722, -34.456"),
Map("year" -> "2015-01-11","total" -> 200,"aprobadas"->140,"days"->33,"formalizadas"->21, "loca"-> "53.722, -34.456"),
Map("year" -> "2015-02-11","total" -> 234,"aprobadas"->94,"days"->28,"formalizadas"->62, "loca"-> "54.722, -34.456"),
Map("year" -> "2015-03-11","total" -> 100,"aprobadas"->91,"days"->10,"formalizadas"->76, "loca"-> "55.722, -34.456"),
Map("year" -> "2015-04-11","total" -> 180,"aprobadas"->78,"days"->33,"formalizadas"->60, "loca"-> "56.722, -34.456"),
Map("year" -> "2015-05-11","total" -> 220,"aprobadas"->50,"days"->12,"formalizadas"->43, "loca"-> "57.722, -34.456"),
Map("year" -> "2015-06-11","total" -> 311,"aprobadas"->55,"days"->28,"formalizadas"->6, "loca"-> "58.722, -34.456"),
Map("year" -> "2015-07-11","total" -> 145,"aprobadas"->65,"days"->28,"formalizadas"->36, "loca"-> "59.722, -34.456"),
Map("year" -> "2015-08-11","total" -> 345,"aprobadas"->58,"days"->23,"formalizadas"->22, "loca"-> "60.722, -34.456"),
Map("year" -> "2015-09-11","total" -> 233,"aprobadas"->70,"days"->21,"formalizadas"->56, "loca"-> "61.722, -34.456"),
Map("year" -> "2015-10-11","total" -> 312,"aprobadas"->190,"days"->22,"formalizadas"->56, "loca"->"62.722, -34.456"),
Map("year" -> "2015-11-11","total" -> 190,"aprobadas"->90,"days"->21,"formalizadas"->44, "loca"->"63.722, -34.456"),
Map("year" -> "2015-12-11","total" -> 194,"aprobadas"->100,"days"->19,"formalizadas"->41, "loca"->"64.722, -34.456")
)
sc.makeRDD(mapa).saveToEs("geolol/geo_point")
}
}
在loca中,我尝试按照文档说明传递带有coordenates的字符串,我假设我必须创建一个索引,告诉该loca类型是geo-point,但我不知道该怎么做。
谢谢大家
最佳答案
如果尚未建立索引,则必须在elasticsearch中自己创建索引,并将"loca"
映射为地理类型。这是来自文档的示例:
PUT /attractions
{
"mappings": {
"restaurant": {
"properties": {
"name": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}
}
默认情况下,它将把您的数字理解为整数并将其索引为它们的数组。