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

Aggregations returned as base64 encoded string (json.RawMessage) #51

Closed
vsiv opened this issue Mar 13, 2015 · 7 comments
Closed

Aggregations returned as base64 encoded string (json.RawMessage) #51

vsiv opened this issue Mar 13, 2015 · 7 comments

Comments

@vsiv
Copy link

vsiv commented Mar 13, 2015

if you json.Marshal(result) on query result with aggregations, the aggregation results are marshaled as a base64 encoded string , whereas the query hits are not, which is a bit of a hassle. You can test it by marshaling the result from a query execution that uses aggregation. I tested with TermsAggregation.

You can solve it by using result.Aggregations... but not for entire result response.

type Aggregations map[string]json.RawMessage

Its because json.RawMessage is not a pointer (reference: https://groups.google.com/forum/#!topic/Golang-Nuts/38ShOlhxAYY).

Changing it to type Aggregations map[string]*json.RawMessage along with its usage in search_aggs.go solves it :) But I am not sure about other ramifications due to this.

If you like this, I can submit a pull request. For now, I have just forked the repo.

Thanks.

@olivere
Copy link
Owner

olivere commented Mar 13, 2015

Thanks for reporting this. You learn a new thing every day. :-)
Yes, maybe I should change that. Give me some time to think about it.

olivere added a commit that referenced this issue Mar 13, 2015
@olivere
Copy link
Owner

olivere commented Mar 13, 2015

Can you test if the issue-51 branch solves the issue for you? If you can, it would be very helpful if you can provide a test for it...

@olivere
Copy link
Owner

olivere commented Mar 13, 2015

FYI: Marshaling results back into JSON is not tested in Elastic. There might be issues with fields not being attributed with omitempty etc. You've been warned :-)

@sevein
Copy link

sevein commented Mar 24, 2015

Thank you so much for this, I was experiencing the same issue today! go get -u et voilà! 👍

@olivere
Copy link
Owner

olivere commented Mar 25, 2015

@sevein My pleasure. May I ask what's your use case for serializing the results back into JSON?

@sevein
Copy link

sevein commented Mar 25, 2015

Of course, @olivere! I was basically doing a bad thing :) i.e. embedding the serialized version of elastic.Aggregations into my HTTP API response. But I've decided to start building my custom response types with its own json tags after seeing your warning in c3351fa. Thanks again!

@vsiv
Copy link
Author

vsiv commented Apr 1, 2015

Thanks! @olivere, sorry was really caught up the last couple weeks... couldn't help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants