Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json4sHitReader should get _id from hit. #2220

Open
hanrw opened this issue Sep 28, 2020 · 3 comments
Open

Json4sHitReader should get _id from hit. #2220

hanrw opened this issue Sep 28, 2020 · 3 comments

Comments

@hanrw
Copy link
Contributor

hanrw commented Sep 28, 2020

    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)
        }
      }
@stale
Copy link

stale bot commented Nov 27, 2020

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.

@stale stale bot added the wontfix label Nov 27, 2020
@stale stale bot closed this as completed Dec 4, 2020
@sksamuel sksamuel reopened this Dec 4, 2020
@stale stale bot removed the wontfix label Dec 4, 2020
@hanrw
Copy link
Contributor Author

hanrw commented Dec 6, 2020

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)
      }
  }

}

@stale
Copy link

stale bot commented Feb 4, 2021

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.

@stale stale bot added the wontfix label Feb 4, 2021
@sksamuel sksamuel closed this as completed Feb 4, 2021
@sksamuel sksamuel reopened this Feb 4, 2021
@stale stale bot removed the wontfix label Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants