# Fetching Records As Result And Haldling

**URL:** <https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948>\
**Category:** Elasticsearch\
**Created:** [May 16, 2020, 7:48pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948 "2020-05-16T19:48:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_layall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_layall/32/46899_2.png) [@Rahul\_layall](https://discuss.elastic.co/u/Rahul_layall)\
**Post date:** [May 16, 2020, 7:48pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/1 "2020-05-16T19:48:47Z")

</div>

GET /index\_name/\_search  
{  
"query" : {  
"match" : {  
"name": "Kumar"  
}  
}  
}

Sir If i run this query then it will give  
value: \<=10,000(if this much or more than that records are there)  
hits: 10

To manage hits we can use "from" : 0, "size" : 10,

But i want to ask you that for using size, i need to pre-define the size value to tell that how much records value i want

Can you tell what can i use as a size value so that it will automatically give/fetch the total number of result value so that i don't need to pre-define the size.

I know that the maximum value should be 10,000  
but if the value if \<=10,000 then should i write any value of size so that it will automatically detect the total record  
Because sometimes we don't know that how much records we will get as result

---

<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:** [May 16, 2020, 8:21pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/2 "2020-05-16T20:21:43Z")

</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:** ![Rahul\_layall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_layall/32/46899_2.png) [@Rahul\_layall](https://discuss.elastic.co/u/Rahul_layall)\
**Post date:** [May 16, 2020, 8:40pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/3 "2020-05-16T20:40:59Z")

</div>

Sir  
what should I use here as size value

size=""

What should I fill the size value so that it will automatically detect the total results values

I don't want to fill the hard-core size value

---

<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:** [May 17, 2020, 4:04pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/4 "2020-05-17T16:04:26Z")

</div>

It's not possible and it does not really make sense as you probably don't want to display to the use a page which has 10m of documents.  
But you want either to:

- Paginate: use from / size
- Do deep pagination: use search after
- Extract all the data for another usage than displaying (compute for example): use scroll

If you have a different use case, could you describe it?

---

<div class="post-metadata">

**Author:** ![Rahul\_layall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_layall/32/46899_2.png) [@Rahul\_layall](https://discuss.elastic.co/u/Rahul_layall)\
**Post date:** [May 17, 2020, 4:53pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/5 "2020-05-17T16:53:24Z")

</div>

Sir,  
Can you please tell me that  
if i have a total result of 37(just taking this value as a example, it can be 997, 9897, etc.)  
and every time i will send a request to my java class in which i will update the values of "from" and "size" like  
from=0, size=10 -----for First iteration  
from=10, size=20 -----for Second iteration  
(i will increment the values of "from" and "size" by 10 after every iteration)  
will it give an error or not when i will be iterating 4th time in which from="30" and size="40" but records will be between \>=30 and \<=40  
as my size value would be 40(size="40") but total records are 37

Other Scenario  
will this way will help me with 10,000+ records because i will fetch only 10 records at a time

---

<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:** [May 18, 2020, 1:59pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/6 "2020-05-18T13:59:33Z")

</div>

> [@Rahul\_layall](#):
>
> will it give an error or not when i will be iterating 4th time in which from="30" and size="40" but records will be between \>=30 and \<=40  
> as my size value would be 40(size="40") but total records are 37

No that's fine.

If you don't want to have small pages, you can also run with `?from=0&size=1000` even if you have only one hit.

> [@Rahul\_layall](#):
>
> will this way will help me with 10,000+ records because i will fetch only 10 records at a time

No. But does the user really want to click on "next page" button 999 times?

---

<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:** [June 15, 2020, 1:59pm UTC](https://discuss.elastic.co/t/fetching-records-as-result-and-haldling/232948/7 "2020-06-15T13:59:43Z")

</div>

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