ruby - Rails elasticsearch aggregation -
Somehow I do not seem to get a response with my aggregates ...
It uses curl As it works:
HBZUMB01 $ curl -XPOST "http: // localhost: 9200 / content / _search" -d '{"size": 0, "ags": {"Sport_count": {"Value_count": {"field": "dwid"}}}} '
I get the answer:
{ "Total": "Total": 5, "Successful": 5, "Failed": 0}, "Hit": {"Total": 90, "max_score": 0.0, However, using code in Rail:
query = '{"size": 0, "aggs" : {"Sport_count": {"value_count": {"field": "dwid"}}} '@response = Content.search (query) To_json
and rendering it in the browser
response_to do format | Presentation of the format.html: "# {@ response}" end
I get an empty response:
[]
How can I print my aggregates here which I got with curls?
I was also struggling with it, but now I came to know how to achieve aggregation results .
If you are using elastic search-rail , the elastic search-model gem, when you run a group on a model, you In this example, you can get the bucket:
agg = Model.search (query: {match: {param: 'value'}}, agus: {my_aggregation_name: {terms: {field: : My_field}}}
In your ROR code:
agg.response ["aggregation" "[" My_aggregation_name "] [" bucket "] < / Code>
With that, you will get a result like this:
[{"key" = & gt; banana, "doc_count" => ; 1963, "score" => 478.3 0 9 20868573355, "Big_Count" = 2152}, {"K12", "Score" = 315.68857496078505, "bg_count" => 1243}, ...]
Then you can do whatever you want! Hope that helps!
Comments
Post a Comment