How to control elasticsearch aggregation results using the From / Size option?

I am trying to add pagination in elasticsearch term aggregation. In the request, we can add pagination as

{ "from": 0, // to add the start to control the pagination "size": 10, "query": { } } 

This is pretty clear, but when I want to add pagination to aggregation, I read a lot about it, but haven't found anything, my code looks like this:

 { "from": 0, "size": 0, "aggs": { "group_by_name": { "terms": { "field": "name", "size": 20 }, "aggs": { "top_tag_hits": { "top_hits": { "size": 1 } } } } } } 

Is there a way to create pagination using a function or any other suggestions?

0
source share
1 answer

It looks like you probably want partitions. From the docs:

Sometimes there are too many unique terms to process in a single request / response pair, so it is useful to split the analysis into multiple requests. This can be achieved by grouping field values ​​into several sections during a request and processing only one section in each request.

Basically you add "include": { "partition": n, "num_partitions": x }, where n is the page and x is the number of pages.

Unfortunately, this feature was added quite recently. If the tags can be trusted in the GitHub Issue that generated this feature, you will need at least Elasticsearch 5.2 or better.

+2
source

All Articles