I am using cloudant-client 2.17.0. I have a partitioned db and want to make a query to get all the documents which match it.
com.cloudant.client.api.Database class's query methods returns a QueryResult object, which has bookmark field in it. I cannot find any query method which takes this bookmark as argument. So do all the query methods (of com.cloudant.client.api.Database) by default return all the documents or is there a query method somewhere which takes this bookmark as argument? If there is such method, how do I get the page size? Cloudant doc mentions, right way to check if a certain page is the last page of result is to check if the result size < page size.
You can set the bookmark in QueryBuilder
helper class and pass that to the Database query
method.
Here's a QueryBuilder example from the java-cloudant API documentation:
QueryBuilder queryBuilder = db.query(new QueryBuilder(and(
gt("Movie_year", 1960),
eq("Person_name", "Alec Guinness"))).
sort(Sort.desc("Movie_year")).
fields("Movie_name", "Movie_year").
bookmark("some-bookmark").
limit(2);
Then you'd pass the query
variable to db.query
where db
is com.cloudant.client.api.Database
QueryResult<Movie> moviesPage = db.query(queryBuilder.build(), Movie.class);
This test case shows how to use bookmark
to get all docs per page: https://github.com/cloudant/java-cloudant/blob/master/cloudant-client/src/test/java/com/cloudant/tests/IndexTests.java#L254-L278.