DocumentMap を使用して一括インデックスを作成しようとしています。私はそのようなクラスをマッピングします
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)
}
そして、これは私がデータにインデックスを付ける方法です(現在、単一のアイテムにのみインデックスを付けることができます)、
val test =jsonValue(0).as[Post]
client.execute {
index into "posts/test" doc test
}
2つの質問があります
1.インデックスを作成する前に、プロパティのコメントをネストされたものとしてマップする必要がありますか?? すべてのリストが単一の文字列としてインデックス化されるためです。
2.投稿オブジェクトのリストにどのようにインデックスを付けることができますか?? 現在、単一のオブジェクトにのみインデックスを付けることができます。
解決
1.最初の非常に重要なことは、インデックスを作成する前にマッピングをクレートすることです。
2.そのような一括インデックスを使用します。
val ops = for (j <- jsonValue) yield index into "posts/test" doc j.as[Post]
client.bulk(ops: _*)
ありがとうミキ