I'm trying to implement pagination of my GraphQL API with ElasticSearch's pagination feature. My pagination implementation in GraphQL API follows Relay specification. As far as I know, search after feature in ES only returns cursors in Relay specification, which can be used to tell ES which item you fetched in the last request.
In Relay specification, client could also check if there are more items in next page with
But how can I implement hasNextPage API without this information from ES?
Composite aggregation has similar pagination feature as search after API, and does not have properties like
Only method I can think of is including integer id in cursor. Pagination initially starts without cursor, so assign 1 to the first item. When the integer id becomes the same number as the total document document, there are no items left. This may not work properly if documents get added or removed in ES, though.