elastic4s
elastic4s copied to clipboard
Json4sHitReader should get _id from hit.
implicit def Json4sHitReader[T](implicit json4s: Serialization, formats: Formats, mf: Manifest[T]): HitReader[T] =
new HitReader[T] {
override def read(hit: Hit): Try[T] = Try {
json4s.read[T](hit.sourceAsString)
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
my solution may not good.
object ElasticJson4s {
object Implicits {
implicit def Json4sHitReader[T](implicit json4s: Serialization, formats: Formats, mf: Manifest[T]): HitReader[T] =
new HitReader[T] {
override def read(hit: Hit): Try[T] = Try {
val metaFields = s"""{"_id": "${hit.id}","_type": "${hit.`type`}","_index": "${hit.index}" ,"_version": "${hit.version}", """
val source = metaFields + hit.sourceAsString.substring(1)
json4s.read[T](source)
}
}
implicit def Json4sAggReader[T](implicit json4s: Serialization, formats: Formats, mf: Manifest[T]): AggReader[T] =
new AggReader[T] {
override def read(json: String): Try[T] = Try {
json4s.read[T](json)
}
}
implicit def Json4sIndexable[T <: AnyRef](implicit json4s: Serialization, formats: Formats): Indexable[T] =
new Indexable[T] {
override def json(t: T): String = json4s.write(t)
}
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.