# Is it always necessary to use size attribute in DSL query?

**URL:** <https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377>\
**Category:** Elasticsearch\
**Created:** [July 27, 2023, 5:37am UTC](https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377 "2023-07-27T05:37:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [July 27, 2023, 5:37am UTC](https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377/1 "2023-07-27T05:37:18Z")

</div>

Hi,

Is it always necessary to use the size attribute in Elasticsearch DSL query?

What if there are many documents and I do not know the exact no of documents that I would need?

I am trying to get the last poll data from Elasticsearch. In the last poll (time \< now-5m), I get large no of docs, sometimes \> 10,000. So how do I get the data without having to specify the size?

Thanks

---

<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:** [July 27, 2023, 10:31am UTC](https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377/2 "2023-07-27T10:31:01Z")

</div>

It depends on what you want to do but the answer is no.

> [@Sheereen](#):
>
> What if there are many documents and I do not know the exact no of documents that I would need?

It will tell you how many docs you have and will return the first 10 by default.

> [@Sheereen](#):
>
> So how do I get the data without having to specify the size?

You can use:

- the [`size` and `from` parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) to display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
- the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#scroll-search-results) if you want to extract a resultset to be consumed by another tool later. (Not recommended anymore)

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [July 27, 2023, 12:49pm UTC](https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377/3 "2023-07-27T12:49:32Z")

</div>

Hi,

Thanks for the reply.

So if I go for the first approach, using size and from parameter, let's say I have to display the results in a table. Then each time the user changes the page number or clicks on next page button, a search query with the corresponding size and from values should be sent to Elasticsearch?

Thanks

---

<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:** [July 27, 2023, 1:23pm UTC](https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377/4 "2023-07-27T13:23:26Z")

</div>

Yes.

---

<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:** [August 24, 2023, 1:24pm UTC](https://discuss.elastic.co/t/is-it-always-necessary-to-use-size-attribute-in-dsl-query/339377/5 "2023-08-24T13:24:16Z")

</div>

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