phuc16102001
phuc16102001

Reputation: 431

How to calculate the current page while using Search After?

Currently, I am working on Elastic Search and doing pagination the data. Particularly, the data is sorted with 2 fields:

With the given page size, I can calculate the number of pages by using track_total_hit. However, the problem is that I cannot calculate the current page because the sort key(date, id) do not contain any information about the index of the records.

I have also considered using the from and size, but the number of my data is higher than 10,000 records. So that is impossible to use them. Also, I don't want to change the default configuration of max_result_window because that will affect the performance.

Do you have any solution to solve this? Thank you!

I have checked:

Upvotes: 0

Views: 714

Answers (2)

vũ quang
vũ quang

Reputation: 1

but I recommend using from and size in the situation you are using paginate because it will help you at a good level because no one paginates 1 page per 1000 lines If you use search after you will get an error if the user edits fix your URL then you will have query problem

Upvotes: 0

phuc16102001
phuc16102001

Reputation: 431

I have researched and figured-out that this is a trade-off.

That is similar to offset-pagination and keyset-pagination of SQL db.

The offset strategy is similar to the Scroll API which need to scan from the beginning, and it knows the current page.

Meanwhile, the search after is similar to the keyset strategy, which do not need to scan from the beginning, but won't know the current page.

Upvotes: 0

Related Questions