Aggregation only on hits returned

First question here, new on Elasticsearch.
Is it possible to do an aggregation on the hits returned on a search? I mean, if there are 8000 docs that match my query but I limit the size to 200, is it possible to do an aggregation using only the 200?

Hi Sidnei. See the sampler aggregation

Thanks a lot Mark. It worked perfectly. :smiley:

Humm I think I was too hurried... in fact it seems that the sampler aggregation has nothing to do with the returned hits. If you use a fixed "size": 200 and change the "from": 0, 200, 400, the hits returned are differente sets, but the agg looks the same and does not reflect the returned hits.

What am I doing wrong?

Generally aggregations don’t follow the current page of results (1-10, 11-20 etc) because they are used to help searchers narrow matches using choices of prices, colours, brands etc from all matches rather than just those visible on the current page.
If you have a fuzzy query or one that allows partial matches with a common term then there can be a very long tail of low quality matches, with the worst case being a match on every doc in the index. In these cases it makes sense to use a sampler aggregation to focus the aggregations on only the most relevant results.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.