Aggregation over a paginated query


I have a question regarding to running an aggregation on a paginated query.

For example, this query:

        "size": 0,
        "from": 100,
        "query": {
            "match_all": {}
        "aggs": {
            "agg_top_hits": {
                "top_hits": {
                    "size": 1,
                    "_source": {
                        "includes": [

In this case the store has only 2 documents.

My question is, shouldn't the aggregation run on the set of matched documents? If my store has only 2 documents, shouldn't the aggregation be empty once the from is over 2?

Aggregations are the full set of docs that matched a query - independent of hit pagination.

If you think back to where aggs/facets came from, e-commerce websites show how many shoe sizes/colours etc are available in a side-bar regardless of what page in the results you're currently on.

Thanks @Mark_Harwood sounds fair.

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