# How to set the limit in for nested aggregations results

**URL:** <https://discuss.elastic.co/t/how-to-set-the-limit-in-for-nested-aggregations-results/174957>\
**Category:** Elasticsearch\
**Created:** [April 2, 2019, 9:27am UTC](https://discuss.elastic.co/t/how-to-set-the-limit-in-for-nested-aggregations-results/174957 "2019-04-02T09:27:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aman\_Kumar2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aman_kumar2/32/43293_2.png) [@Aman\_Kumar2](https://discuss.elastic.co/u/Aman_Kumar2)\
**Post date:** [April 2, 2019, 9:27am UTC](https://discuss.elastic.co/t/how-to-set-the-limit-in-for-nested-aggregations-results/174957/1 "2019-04-02T09:27:02Z")

</div>

How can I set the total result limit for my nested aggregations results. I have looked into the composite aggregations but it gives me error as I am using geo\_distance aggregation and composite aggregation doesn't support geo\_distance aggregations

My Code:

```auto
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "nested": {
                  ....
                  ....
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "nested": {
                  ....
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        }
      ]
    }
  },
  "aggs": {
    "geoDistance": {
      "geo_distance": {
        "field": "location",
        ...
        ...
      },
      "aggs": {
        "dayRange": {
          "date_histogram": {
            ...
            ...
          },
          "aggs": {
                "top_users": {
                  "top_hits": {
                    "sort": [
                      {
                        "score": {
                          "order": "desc"
                        }
                      }
                    ],
                    "size": 15
                  }
                }
              }
        }
      }
    }
  }
}

```

Here I have set the size 15 but I guess it set the limit in every buckets results and what I whats to achieves is that total doc\_count limit should be 15.

---

<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:** [April 30, 2019, 9:27am UTC](https://discuss.elastic.co/t/how-to-set-the-limit-in-for-nested-aggregations-results/174957/2 "2019-04-30T09:27:04Z")

</div>

Closed on April 30, 2019, 9:27am UTC

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