문서 필드에 나타나는 키워드를 기반으로 문서를 검색하는 API가 있습니다. 요청을 보내는 클라이언트에게 문서를 반환하고 원하는 경우 더 많은 문서를 요청할 수 있도록 결과 페이지를 매기고 싶습니다. 쿼리 자체는 Azure 데이터 탐색기에있을 때 브라우저에서 1 초 정도 밖에 걸리지 않지만 Python DocumentDB 라이브러리를 사용하여 쿼리 할 때는 1 분 정도 걸립니다.
Microsoft Cosmos DB REST API를 살펴보면 사용 되는 두 개의 토큰 인 x-ms_continuation 및 x-ms-max-item-count 가있는 것처럼 보입니다 .
옵션 사전에 항목으로 넣는 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})
나는 또한 int 대신 문자열을 사용해 보았습니다 maxItemCount
.
여기서 내가 뭘 잘못하고 있니?
편집 : 헤더는 http_constants.py의 위 문서에서 두 개와 동일합니다 .
# Our custom DocDB headers
Continuation = 'x-ms-continuation'
PageSize = 'x-ms-max-item-count'
쿼리 결과는 결과 개체 자체에서 처리 _fetch_function(options)
해야하며 메서드 를 호출해야합니다.
q = client.QueryDocuments(collection_link, query, {'maxItemCount':10})
results_1 = q._fetch_function({'maxItemCount':10})
#this is a string representing a JSON object
token = results_1[1]['x-ms-continuation']
results_2 = q._fetch_function({'maxItemCount':10,'continuation':token})
데이터가에 포함되고 results_[n][0]
호출에서 반환 된 헤더 정보가에 반환됩니다 results_[n][1]
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다