val map=scala.collection.mutable.Map[String,AnyRef]() map.put("age","26".toLong.asInstanceOf[AnyRef]) map.put("name","ll") val map2=scala.collection.JavaConversions.mutableMapAsJavaMap(map) val indexRequest = new IndexRequest("hyj2017", "test","bbb").source(map2) proos.add(indexRequest) proos.awaitClose(10, TimeUnit.SECONDS); client.close()
Solve the problem of long type when scala calls api to operate elasticsearch
When writing a spark program in scala, in order to facilitate control, the java api will be called to operate elasticsearch. At this time, a map is needed to receive specific fields. There is a problem here, that is, the accepted map must be of type AnyRef , For example, we need to store a value of type long, such as time is a long, then there will be a problem with direct writing, because AnyRef in scala does not contain a numerical type, but belongs to the AnyVal type. In this case, we use the following method to force conversion to solve this problem
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327048181&siteId=291194637
Recommended
Ranking