# Limit the result of Elasticsearch query

**URL:** <https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051>\
**Category:** Elasticsearch\
**Created:** [July 8, 2016, 1:14pm UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051 "2016-07-08T13:14:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajkamalkool6](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rajkamalkool6](https://discuss.elastic.co/u/rajkamalkool6)\
**Post date:** [July 8, 2016, 1:14pm UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051/1 "2016-07-08T13:14:12Z")

</div>

Hi,

I wrote one elasticsearch query to get only top 10 result in descending order

`{ "size": 10, "aggs": { "group_by_user": { "terms": { "field": "user.raw" } } } }`

I am getting the following error`Result window is too large, from + size must be less than or equal to: [10000] but was [10250]`

How to rephrase my query to get the exact result of what I am looking for it.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [July 8, 2016, 5:24pm UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051/2 "2016-07-08T17:24:37Z")

</div>

This is quite odd.

Are you certain the query you provided is the complete and accurate search that received that error?

---

<div class="post-metadata">

**Author:** ![rajkamalkool6](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rajkamalkool6](https://discuss.elastic.co/u/rajkamalkool6)\
**Post date:** [July 11, 2016, 10:09am UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051/3 "2016-07-11T10:09:31Z")

</div>

@Glen_Smith. I am not sure whether my query is perfect enough to satisfy my requirement .

---

<div class="post-metadata">

**Author:** ![byronvoorbach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byronvoorbach/32/8283_2.png) [@byronvoorbach](https://discuss.elastic.co/u/byronvoorbach)\
**Post date:** [July 11, 2016, 12:17pm UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051/4 "2016-07-11T12:17:18Z")

</div>

You should place the 'size' param inside the 'group\_by\_user' instead of outside the 'agg' block, then it will work. Top level size applies to query results, not aggregation results 🙂

```
{
  "aggs": {
    "group_by_user": {
      "terms": {
        "field": "user.raw",
         "size": 10
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![rajkamalkool6](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rajkamalkool6](https://discuss.elastic.co/u/rajkamalkool6)\
**Post date:** [July 11, 2016, 12:44pm UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051/5 "2016-07-11T12:44:29Z")

</div>

> [@byronvoorbach](#):
>
> {  
> "aggs": {  
> "group\_by\_user": {  
> "terms": {  
> "field": "user.raw",  
> "size": 10  
> }  
> }  
> }  
> }

I am getting the below error,  
`Result window is too large, from + size must be less than or equal to: [10000] but was [10010]`

---

<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:** [July 5, 2017, 10:36pm UTC](https://discuss.elastic.co/t/limit-the-result-of-elasticsearch-query/55051/6 "2017-07-05T22:36:34Z")

</div>


