meilisearch-go icon indicating copy to clipboard operation
meilisearch-go copied to clipboard

a `json.RawMessage` search response's hit fields

Open trim21 opened this issue 3 years ago • 4 comments

Previous I'm using a es client to search.

This es client has a feature that it's search response's hit field has s Source field with json.RawMessage field, contain the raw bytes from API.

And so I can unmarshal it to the struct I'm expecting.

It's SDK api look like this:

		result, err := es.search(...)
		if err != nil {
			return errgo.Wrap(err, "search")
		}

		for i, hit := range result.Hits.Hits {
			var source = Subject{}
// and hit.Source is a json.RawMesssage, So I can unmarshal it here.
			err = json.Unmarshal(hit.Source, &source)
			if err != nil {
				return err
			}

(it's source https://github.com/olivere/elastic/blob/e5be2e003d85f8b9bf2c97662e34c6a857f60a61/search.go#L779)

But, currently, meilisearch's SearchResponse.Hits is a []interface{}, so I'll need to do many type case or marshal to json bytes then unmarshal to back.

Hope there could be some API improvement on this.

Or I hope it's possible I can get the raw response bytes somehow so I can unmarshal from the response directly.

trim21 avatar Aug 14 '22 05:08 trim21

Hi @Trim21, Yes, this could be a very good addition to this repo 🚀 ! For the moment it is not in our priorities unfortunately to modify this repo because others are not yet updated with the last release. Thanks for your suggestion ❤️

alallema avatar Aug 25 '22 19:08 alallema

@alallema , can I work on this issue? Where to start with for this issue in the source code?

26tanishabanik avatar Oct 13 '22 14:10 26tanishabanik

this is a really useful feature, and current API return type is really pain in the ass.

Even only add a new field in response containing the raw bytes of http body is enough to resolve this.

trim21 avatar Oct 13 '22 18:10 trim21

Hi @26tanishabanik, Thanks for proposing, like @trim21 you can:

  • add a new field in the SearchResponse response structure that contains the raw response
  • create a new method called SearchRaw() which is exactly the same as the Search() method but instead of returning a SearchResponse it returns the raw response.

I prefer the second method but if you have trouble with it, you can choose the first option.

alallema avatar Oct 14 '22 14:10 alallema

Hi @26tanishabanik are you still interested in working this issue? otherwise I can take a look

ginglis13 avatar Oct 20 '22 21:10 ginglis13

Hi @ginglis13, No one seems to work on this issue right now. We prefer not assigning people to our issues because sometimes people ask to be assigned and never come back, which discourages volunteer contributors to open a PR to fix this issue. We will accept and merge the first PR that fixes correctly and well implements the issue following our contributing guidelines. We are looking forward to reviewing your PR.

alallema avatar Oct 24 '22 08:10 alallema

Any release plan?

trim21 avatar Nov 08 '22 08:11 trim21

Any release plan?

I just created it here

alallema avatar Nov 08 '22 08:11 alallema