Searchkick: Sub-aggregations

Created on 29 Dec 2017  路  3Comments  路  Source: ankane/searchkick

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.

Most helpful comment

Great suggestion @gerrywastaken 馃憤 Added.

All 3 comments

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
https://github.com/ankane/searchkick/issues/976#issuecomment-324533048 .

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.

Great suggestion @gerrywastaken 馃憤 Added.

@ankane Thanks :)

Was this page helpful?
0 / 5 - 0 ratings