-
Notifications
You must be signed in to change notification settings - Fork 801
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
Can't access aggregations correctly on Elasticsearch::Model::Response #568
Comments
There is working playground https://gist.github.com/schovi/96755a56fe797c1530363d82a14be688 just put it in any rails project and run It seems you use Hashie library only for easily accessible Hash? This library seems pretty large and complex just for one thing. Why not to use ActiveSupport::HashWithIndifferentAccess when we are already in rails or what I personally prefer something like: https://github.com/aetherknight/recursive-open-struct/? |
Nice catch! :) The underlying problem is probably because h = { foo: 'bar' }
# => {:foo=>"bar"}
h.min
# => [:foo, "bar"]
h.max
# => [:foo, "bar"] I'll have a look into it. |
@karmi: Same problem with HashWithIndifferentAccess or any other Hash like object. Worst part on that is that anybody can monkey patch Enumerable or/and any class and module and then something will suddenly stop working. Example with same problem on HashWithIndifferentAccess and then all "unavailable properties" on Hashie::Mash instance.
Structs or custom class seems like only solution. |
Yeah, it's bad. I started playing with it, but the whole thing of course screams "recursion", since we cannot just wrap the aggregations Hash, we have to dive deep into every value. Of course, we cannot re-define I'm not hell-bent on At the moment, it seems to me like the former approach, ie. wrapping or enhancing the values of |
So, I have looked into it, and seems like we can simply recursively traverse the values of the I've added a dedicated I've added a unit test for the behaviour, and amended the integration test. Thanks for the report and for all the debugging information, @schovi! Closed in 6d10abb |
Github seems to be eating the changes, so another try. I've created a wrapper class I've added a unit test, and update the integration test suite. Closed in commit 6d10abb. |
…unexpected values While people can define names for aggregations such as `min` and `max`, these methods are defined in `Enumerable#min` and `Enumerable#max`, and return an unexpected value: result.aggregations # => {"price"=>{"doc_count"=>9428, "min"=>{"value"=>1.0}, "max"=>{"value"=>260000.0}}} result.aggregations.price # => {"doc_count"=>9428, "min"=>{"value"=>1.0}, "max"=>{"value"=>260000.0}} result.aggregations.price.min # => ["doc_count", 9428] Therefore, the whole Hash with aggregations is being traversed, in a wrapper class, and a `min` and `max` method is defined for Hashie::Mash instances, because these names are too common. The wrapper class can have its uses further down the line, so a dedicated unit test file has been added as well. Closes #568 Related: elastic/elasticsearch-ruby#306
Original issue: elastic/elasticsearch-ruby#306
I am having single query with 2 nested aggregations
Calling elastic and getting result directly works perfectly, but when using ruby api it behave really strange:
I see 2 problems there
aggregations.price.max
returns content of aggregationmin
["min", {"value" => 1.0}]
where I expect another hashI was able to trace it to Hashie library, where similiar behaviour with returning array is https://github.com/intridea/hashie#methodaccesswithoverride but there my struggle ends.
Setup Ruby 2.3, Rails 5.0.0.beta3, sidekiq 4 and nothing more special
The text was updated successfully, but these errors were encountered: