Search code examples
elasticsearchnestelasticsearch-aggregation

What is the correct way to get Nth page's datas for composite aggregation in elasticsearch?


We can do pagination for composite aggregation using with "After" . However, when we use "After", it gives us just next page. How can we get directly Nth page's or previous page's datas?

GET /_search
{
    "aggs" : {
        "my_buckets": {
            "composite" : {
                "size": 2,
                 "sources" : [
                    { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
                    { "product": { "terms": {"field": "product", "order": "asc" } } }
                ],
                "after": { "date": 1494288000000, "product": "mad max" } 
            }
        }
    }
}

Solution

  • No it's not possible to request a specific page directly, you need to paginate until you get to the "page" that you need.