# Fetch command in elasticsearch queries, limit query results

**URL:** <https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179>\
**Category:** Elasticsearch\
**Created:** [July 14, 2020, 6:16pm UTC](https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179 "2020-07-14T18:16:40Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![liron\_gofberg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liron_gofberg/32/59823_2.png) [@liron\_gofberg](https://discuss.elastic.co/u/liron_gofberg)\
**Post date:** [July 18, 2020, 3:31pm UTC](https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179/21 "2020-07-18T15:31:48Z")

</div>

Cristian, please

I don’t care how much time it will takes  
I just want to do it the right way  
The optimal way

I’m using only filters term queries  
All my queries are similar  
And all of them return millions of records  
I just want to let the user fetch millions of records and to let him decide how much results he wants to get out of the full result

Each document has 40 fields , I want to getch them all

1.what is the right solution to fetch millions of records?  
2.how can I fetch only specific number of results out of the full result ?

If user wants more than 10000 results, you don’t have a feature to get just part of the results? So user will get accurate specific number of records out of the whole search result?(when results number is bigger than 10000)

I would like to get a low latency  
But if it’s not possible to do it fast it’s ok  
I just want to know how to do it

Terminate\_after doesn’t help to get accurate number of results , its operation is on the shard level

You tell me that scroll don’t need to fetch such amount of data do  
So what can do that?🙏🏻

Concurrency : max 30  
And most of the time much less than 30  
No updates  
Deletion data will be rare  
Indexing rate - few millions per a day

I saw multiple posts talking about fetching millions of records but no one tells how  
And no one tells how to get accurate results number out of the full result

Is search after is the right solution for fetching millions of records?  
Scroll ?

---

<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 18, 2020, 4:09pm UTC](https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179/22 "2020-07-18T16:09:01Z")

</div>

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/search-request-search-after.html) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) if you want to extract a resultset to be consumed by another tool later.

---

<div class="post-metadata">

**Author:** ![liron\_gofberg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liron_gofberg/32/59823_2.png) [@liron\_gofberg](https://discuss.elastic.co/u/liron_gofberg)\
**Post date:** [July 18, 2020, 4:43pm UTC](https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179/23 "2020-07-18T16:43:41Z")

</div>

Thanks,  
so search after is the right solution to get millions of results  
Then I can insert the results into data frame

It will be optimal if I will configure Elasticsearch to sort the documents?  
I saw example of reading 1 page only  
Do you have example of reading 2 pages or more?  
Please🙏🏻

Thanks

---

<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 15, 2020, 4:43pm UTC](https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179/24 "2020-08-15T16:43:42Z")

</div>

Closed on August 15, 2020, 4:43pm UTC

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

[Previous page](https://discuss.elastic.co/t/fetch-command-in-elasticsearch-queries-limit-query-results/241179.md?page=1)
