# How to paging the buckets after aggregation

**URL:** <https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577>\
**Category:** Elasticsearch\
**Created:** [October 30, 2018, 7:40am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577 "2018-10-30T07:40:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamazy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamazy/32/36501_2.png) [@iamazy](https://discuss.elastic.co/u/iamazy)\
**Post date:** [October 30, 2018, 7:40am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/1 "2018-10-30T07:40:01Z")

</div>

I remove the duplicate result and got the final result of this format, how to paging ths buckets ?

```
"aggregations": {
    "ip_aggs": {
      "doc_count_error_upper_bound": 1391,
      "sum_other_doc_count": 5071763,
      "buckets": [
        {
          "key": "94.187.31.58",
          "doc_count": 1459,
          "top_hits": {。。。}
        },
       {
          "key": "94.187.31.58",
          "doc_count": 1459,
          "top_hits": {。。。}
        },
       {
          "key": "94.187.31.58",
          "doc_count": 1459,
          "top_hits": {。。。}
        },
      {
          "key": "94.187.31.58",
          "doc_count": 1459,
          "top_hits": {。。。}
        },
       {
          "key": "94.187.31.58",
          "doc_count": 1459,
          "top_hits": {。。。}
        },
       {
          "key": "94.187.31.58",
          "doc_count": 1459,
          "top_hits": {。。。}
        }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [October 30, 2018, 10:09am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/2 "2018-10-30T10:09:40Z")

</div>

Hi,

Please:  
1°/ Expose your problem  
2°/ Format your code  
3°/ Give your versions  
4°/ Say "hi", "thanks" and "bye"

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html)

bye,  
Xavier

---

<div class="post-metadata">

**Author:** ![iamazy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamazy/32/36501_2.png) [@iamazy](https://discuss.elastic.co/u/iamazy)\
**Post date:** [November 14, 2018, 5:36am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/3 "2018-11-14T05:36:53Z")

</div>

Thanks for telling me this, the code is format ,es version is 5.6.4,  
the problem is the buckets name ip\_aggs has too long length,i want to page it

Thanks a million

bye

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [November 14, 2018, 7:54am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/4 "2018-11-14T07:54:44Z")

</div>

Hi, can you paste the code of your query to see how is done your aggregation ?

bye,  
Xavier

---

<div class="post-metadata">

**Author:** ![iamazy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamazy/32/36501_2.png) [@iamazy](https://discuss.elastic.co/u/iamazy)\
**Post date:** [November 14, 2018, 3:39pm UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/5 "2018-11-14T15:39:01Z")

</div>

hello，thanks a lot，the query is as follow

```
POST search-v1/info/_search
{
  "size": 0, 
  "query": {
    "match_all": {}
  },
  "aggs": {
    "ip_aggs": {
      "terms": {
        "field": "ip",
        "size": 1000
      },
      "aggs": {
        "top_hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

```

i want to page the aggs result

bye

iamazy

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [November 14, 2018, 7:18pm UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/6 "2018-11-14T19:18:08Z")

</div>

Hi,

You should read the doc here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)

If you want to retrieve **all** terms or all combinations of terms in a nested `terms` aggregation you should use the [Composite](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html) aggregation which allows to paginate over all possible terms rather than setting a size greater than the cardinality of the field in the `terms` aggregation. The `terms` aggregation is meant to return the `top` terms and does not allow pagination.

Note that your results are pretty strange, because bucket =\> "key": "94.187.31.58", should be different on each result...

bye,  
Xavier

---

<div class="post-metadata">

**Author:** ![iamazy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamazy/32/36501_2.png) [@iamazy](https://discuss.elastic.co/u/iamazy)\
**Post date:** [November 15, 2018, 8:58am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/7 "2018-11-15T08:58:12Z")

</div>

hello xavier，  
thanks again，  
i removed the key information of result and converted into the same

bye  
iamazy

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 13, 2018, 8:58am UTC](https://discuss.elastic.co/t/how-to-paging-the-buckets-after-aggregation/154577/8 "2018-12-13T08:58:14Z")

</div>

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