Im trying to create bulk index by using DocumentMap . i map the classes like that
case class Comment(id: String, fromId: String, fromName: String, message: String, creationTime: String, likeCount: Int =0)
extends DocumentMap {
def map = Map("id" -> id, "fromId" -> fromId, "fromName" -> fromName, "message" -> message, "createdTime" -> creationTime, "likeCont" -> likeCount)
}
case class Post(id: String, fromId: String, fromName: String, message: String, fullUrl: String, createdTime: String, updateTime: String, likeCont: Int= 0, comments: List[Comment] = Nil)
extends DocumentMap {
def map = Map("id" -> id, "fromId" -> fromId, "fromName" -> fromName, "message" -> message, "fullUrl" -> fullUrl, "createdTime" -> createdTime, "updateTime" -> updateTime, "likeCount" -> likeCont,
"comments" -> comments)
}
And this is how im indexing the data (now i can only index single item),
val test =jsonValue(0).as[Post]
client.execute {
index into "posts/test" doc test
}
I have two questions
1.Should i map the property comments as nested before indexing ?? because now all the list is indexed as a single string.
2.How can index a list of post object?? now i can only index single object.
solution
1.first and very important crate a mapping before indexing.
2.use bulk index like that.
val ops = for (j <- jsonValue) yield index into "posts/test" doc j.as[Post]
client.bulk(ops: _*)
thanks miki