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

Sub-aggregations #1047

Closed
gerrywastaken opened this Issue Dec 29, 2017 · 3 comments

Comments

2 participants
@gerrywastaken

gerrywastaken commented Dec 29, 2017

Is it possible to do sub aggregations like this:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html

I tried to do something like this and hoped to get the product name and price for the highest price android, watch, tablet and phone.

Product.search(
  'Android',
  aggs: {
    product_type: {
      limit: 3,
      aggs: {
        top_hits: {
          sort: :price,
          select: [:product_name, :price],
          size: 1
        }
      }
    }
  },
  limit: 1,
  load: false
)

But in the query that was generated, it was like I had never even added the sub aggregation.

@gerrywastaken

This comment has been minimized.

Show comment
Hide comment
@gerrywastaken

gerrywastaken Dec 30, 2017

Ah! I just found the following, by searching for "top_hits":

Thanks @tiagoamaro 💯 Confirmed that body_options is the best way to do sub-aggregations (the aggs option doesn't support them).
-- @ankane
#976 (comment) .

Any chance that quote and a link to the issue could be added to the docs for aggregations? It's very confusing given that the sub aggregation is just silently removed.

gerrywastaken commented Dec 30, 2017

Ah! I just found the following, by searching for "top_hits":

Thanks @tiagoamaro 💯 Confirmed that body_options is the best way to do sub-aggregations (the aggs option doesn't support them).
-- @ankane
#976 (comment) .

Any chance that quote and a link to the issue could be added to the docs for aggregations? It's very confusing given that the sub aggregation is just silently removed.

@ankane ankane closed this in cc0d263 Dec 30, 2017

@ankane

This comment has been minimized.

Show comment
Hide comment
@ankane

ankane Dec 30, 2017

Owner

Great suggestion @gerrywastaken 👍 Added.

Owner

ankane commented Dec 30, 2017

Great suggestion @gerrywastaken 👍 Added.

@gerrywastaken

This comment has been minimized.

Show comment
Hide comment
@gerrywastaken

gerrywastaken commented Jan 6, 2018

@ankane Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment