# How can I get next buckets by aggregations?

**URL:** <https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100>\
**Category:** Elasticsearch\
**Created:** [December 15, 2016, 2:02am UTC](https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100 "2016-12-15T02:02:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![withccm](https://avatars.discourse-cdn.com/v4/letter/w/a87d85/32.png) [@withccm](https://discuss.elastic.co/u/withccm)\
**Post date:** [December 15, 2016, 2:02am UTC](https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100/1 "2016-12-15T02:02:02Z")

</div>

GROUP BY geoip.country\_name.keyword

```auto
curl -XPOST 'http://abcd:9200/logstash-2016.12.07/_search?pretty' -d '
{
    "size" : 0,
    "aggs" : {
        "group_country" : {
            "terms": {
              "field" : "geoip.country_name.keyword"
            }
        }
    }
}'

```

I get the following:

```auto
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 22442144,
    "max_score" : 0.0,
    "hits" : []
  },
  "aggregations" : {
    "group_country" : {
      "doc_count_error_upper_bound" : 94011,
      "sum_other_doc_count" : 4513408,
      "buckets" : [
        {
          "key" : "United States",
          "doc_count" : 8504290
        },
        {
          "key" : "China",
          "doc_count" : 1810752
        },
        {
          "key" : "Japan",
          "doc_count" : 1101575
        },
        {
          "key" : "United Kingdom",
          "doc_count" : 669897
        },
        {
          "key" : "Germany",
          "doc_count" : 646917
        },
        {
          "key" : "Republic of Korea",
          "doc_count" : 599331
        },
        {
          "key" : "France",
          "doc_count" : 445700
        },
        {
          "key" : "Brazil",
          "doc_count" : 441536
        },
        {
          "key" : "Canada",
          "doc_count" : 425543
        },
        {
          "key" : "Italy",
          "doc_count" : 290951
        }
      ]
    }
  }
}

```

Top 10 results are exposed.  
I want to get next buckets.  
**How can I get next buckets?**

This is not working.

```auto
curl -XPOST 'http://abcd:9200/logstash-2016.12.07/_search?pretty' -d '
{
    "size" : 0,
    "aggs" : {
        "group_country" : {
            "terms": {
              "field" : "geoip.country_name.keyword"
            },
           "size" : 20
        }
    }
}'

```

I got error result.

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "Expected [START_OBJECT] under [size], but got a [VALUE_NUMBER] in [group_country]",
        "line" : 9,
        "col" : 22
      }
    ],
    "type" : "parsing_exception",
    "reason" : "Expected [START_OBJECT] under [size], but got a [VALUE_NUMBER] in [group_country]",
    "line" : 9,
    "col" : 22
  },
  "status" : 400
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 15, 2016, 6:49am UTC](https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100/2 "2016-12-15T06:49:21Z")

</div>

PUT "size" at the same level as "field"

---

<div class="post-metadata">

**Author:** ![haizaar](https://avatars.discourse-cdn.com/v4/letter/h/3d9bf3/32.png) [@haizaar](https://discuss.elastic.co/u/haizaar)\
**Post date:** [December 15, 2016, 7:23am UTC](https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100/3 "2016-12-15T07:23:44Z")

</div>

And setting size to 0 will return you all of the buckets, but be careful with that.

---

<div class="post-metadata">

**Author:** ![withccm](https://avatars.discourse-cdn.com/v4/letter/w/a87d85/32.png) [@withccm](https://discuss.elastic.co/u/withccm)\
**Post date:** [December 15, 2016, 9:36am UTC](https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100/4 "2016-12-15T09:36:09Z")

</div>

I got wanted result.  
Thank you.

---

<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:** [January 12, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-can-i-get-next-buckets-by-aggregations/69100/5 "2017-01-12T09:36:15Z")

</div>

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