Fetching Records As Result And Haldling

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

You can use:

  • the size and from parameters 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 feature to do deep pagination.
  • the Scroll API if you want to extract a resultset to be consumed by another tool later.

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

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?

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

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.

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

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