I have an API that retrieves documents based on keywords that appear in document fields. I would like to paginate results so that I can return documents to a client sending a request, as well as allowing them to request more documents if they want. The query itself only takes a second or so in the browser when I am in the Azure Data Explorer, but it takes about a minute when I query using the Python DocumentDB library.
Looking at the Microsoft Cosmos DB REST API, it appears as if there are two tokens, x-ms_continuation and x-ms-max-item-count that are used.
It doesn't appear that putting these as entries in the options dictionary of document_client.QueryDocuments()
does the trick.
In the GitHub repository, the Read() method references the options parameter:
headers = base.GetHeaders(self,
initial_headers,
'get',
path,
id,
type,
options)
# Read will use ReadEndpoint since it uses GET operation
url_connection = self._global_endpoint_manager.ReadEndpoint
result, self.last_response_headers = self.__Get(url_connection,
path,
headers)
Looking in base.py, where the file is located, I saw these two blocks of code
if options.get('continuation'):
headers[http_constants.HttpHeaders.Continuation] = (
options['continuation'])
if options.get('maxItemCount'):
headers[http_constants.HttpHeaders.PageSize] = options['maxItemCount']
This would appear to correspond to the two parameters above. However, when I set them as options in the query ({'continuation':True,'maxItemCount':10}
), nothing changes.
The final query looks like
client.QueryDocuments(collection_link, query, {'continuation':True,'maxItemCount':10})
I have also tried using a string instead of an int for maxItemCount
.
What am I doing incorrectly here?
Edit: The headers are the same as the two from the documentation above, from http_constants.py:
# Our custom DocDB headers
Continuation = 'x-ms-continuation'
PageSize = 'x-ms-max-item-count'