# Why does using ?size=1000000 increase query latency 100X when totalHits is only 10

**URL:** <https://discuss.elastic.co/t/why-does-using-size-1000000-increase-query-latency-100x-when-totalhits-is-only-10/32314>\
**Category:** Elasticsearch\
**Created:** [October 15, 2015, 7:44pm UTC](https://discuss.elastic.co/t/why-does-using-size-1000000-increase-query-latency-100x-when-totalhits-is-only-10/32314 "2015-10-15T19:44:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikita\_Tovstoles](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Nikita\_Tovstoles](https://discuss.elastic.co/u/Nikita_Tovstoles)\
**Post date:** [October 15, 2015, 7:44pm UTC](https://discuss.elastic.co/t/why-does-using-size-1000000-increase-query-latency-100x-when-totalhits-is-only-10/32314/1 "2015-10-15T19:44:14Z")

</div>

I noticed if I specify a very high size query param for the below query, the response latency increases 100x (2ms to 200-500ms) when running locally. The total doc count is ~ 1000, totalhits for this particular query is only 10. Why the increase?

Thank you,

-nikita

```
{
  "query": {
    "bool": {
      "should": {
        "nested": {
          "query": {
            "term": {
              "brand.id": 551
            }
          },
          "path": "brand"
        }
      }
    }
  },
  "_source": false
}
```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 15, 2015, 8:01pm UTC](https://discuss.elastic.co/t/why-does-using-size-1000000-increase-query-latency-100x-when-totalhits-is-only-10/32314/2 "2015-10-15T20:01:47Z")

</div>

> [@Nikita\_Tovstoles](#):
>
> I noticed if I specify a very high size query param for the below query, the response latency increases 100x (2ms to 200-500ms) when running locally. The total doc count is ~ 1000, totalhits for this particular query is only 10. Why the increase?

The array that collects the hits during the search phase is allocated up front. There is work around for this that only allocates `max(total_docs_on_shard, requested_docs)` up front but its still dangerous to do that because if you did have a ton of documents then it'd be slow again.

---

<div class="post-metadata">

**Author:** ![Nikita\_Tovstoles](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Nikita\_Tovstoles](https://discuss.elastic.co/u/Nikita_Tovstoles)\
**Post date:** [October 15, 2015, 10:17pm UTC](https://discuss.elastic.co/t/why-does-using-size-1000000-increase-query-latency-100x-when-totalhits-is-only-10/32314/3 "2015-10-15T22:17:50Z")

</div>

Thanks, Nik; makes sense.

---

<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, 11:44pm UTC](https://discuss.elastic.co/t/why-does-using-size-1000000-increase-query-latency-100x-when-totalhits-is-only-10/32314/4 "2017-07-05T23:44:30Z")

</div>


