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

HitReader supplies Hit trait not SearchHit #2374

Open
pwheimann opened this issue Mar 31, 2021 · 1 comment
Open

HitReader supplies Hit trait not SearchHit #2374

pwheimann opened this issue Mar 31, 2021 · 1 comment

Comments

@pwheimann
Copy link

I've just started using elastic4s and I have an issue with supplying a HitReader[T] implicit to marshal responses to my domain types. The issue is that the HitReader[T] typeclass provides instances of trait Hit not SearchHit and I need to get the sort values, and Hit doesn't expose this, but SearchHit does.

What I did was simply cast Hit to SearchHit and grab the sort values I need, like so...

    override def read(hit: Hit): Try[Location] = {
      val searchHit = hit.asInstanceOf[SearchHit]
      val distance = searchHit.sort.get(0).asInstanceOf[Double]
      val source = hit.sourceAsMap

This works, but it seems like there should be a better way, should the sort values be exposed in the Hit trait? Or perhaps there is a better/preferred way to do this that I'm just not seeing?

I'm using release 7.9.2 as I'm on Elasticsearch 7.9 currently.

@sksamuel
Copy link
Collaborator

This is a good point. I'll make a change in the 8.0 release where I can change the API a bit.

@sksamuel sksamuel added this to the 8.0 milestone Mar 31, 2021
hmagrahi pushed a commit to hmagrahi/elastic4s that referenced this issue Dec 11, 2023
sksamuel added a commit that referenced this issue Dec 14, 2023
Co-authored-by: Haikel magrahi <haikelmagrahi@haikels-macbook-pro.home>
Co-authored-by: Sam <sam@sksamuel.com>
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