我有一个 API,可以根据文档字段中出现的关键字检索文档。我想对结果进行分页,以便我可以将文档返回给发送请求的客户,并允许他们在需要时请求更多文档。当我在 Azure 数据资源管理器中时,查询本身在浏览器中只需要一秒钟左右的时间,但当我使用 Python DocumentDB 库进行查询时,则需要大约一分钟的时间。
看着Microsoft Cosmos DB REST API,看起来好像有两个令牌,x-ms_延续 and x-ms-最大项目数所使用的。
似乎没有将这些作为条目放入options字典的document_client.QueryDocuments()
就可以了。
在 GitHub 存储库中,Read()方法参考了options范围:
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)
寻找base.py,文件所在的位置,我看到了这两块代码
if options.get('continuation'):
headers[http_constants.HttpHeaders.Continuation] = (
options['continuation'])
if options.get('maxItemCount'):
headers[http_constants.HttpHeaders.PageSize] = options['maxItemCount']
这似乎对应于上面的两个参数。但是,当我将它们设置为查询中的选项时({'continuation':True,'maxItemCount':10}
), 没有什么变化。
最终查询看起来像
client.QueryDocuments(collection_link, query, {'continuation':True,'maxItemCount':10})
我也尝试过使用字符串而不是 intmaxItemCount
.
我在这里做错了什么?
编辑:标题与上面文档中的两个相同,来自http_constants.py:
# Our custom DocDB headers
Continuation = 'x-ms-continuation'
PageSize = 'x-ms-max-item-count'