我有一个类,我想使用 Scala 客户端 elastic4s 开始对 ElasticSearch 进行索引。我扩展了 DocumentMap 以允许我插入文档。String、Int 等简单值正在工作,但我似乎无法正确映射另一个类的列表。
文档看起来与此类似:
case class AThing(UserName: String, Comment: String, Time: String)
extends DocumentMap {
override def map: Map[String, Any] = Map(
"UserName" -> UserName,
"Comment" -> Comment,
"Time" -> Time
)
}
case class ThingsThatHappened(Id: String, Things: Seq[AThing] = Nil)
extends DocumentMap {
override def map: Map[String, Any] = Map(
"Id" -> Id,
"Things" -> Things
)
}
它将在 elasticsearch 中很好地映射 Id 字段,但是当将文档插入到 elasticsearch 中时,我得到一个看起来类似于此的不正确值:
List(AThing(id_for_the_thing,user_name_a,typed_in_comment,2015-03-12))
显然这是错误的,一旦它被插入到 elasticsearch 中,我期待与这个 JSON 结构类似的东西,例如:
"events" : [
{
"UserName" :"user_name_a",
"Comment": "typed_in_comment",
"Time": "2015-03-12"
}
]
有谁知道在使用 elastic4s 索引数据时映射复杂类型数组的方法?