Cassandra的Stargate文档API分页

nnvyjq4y  于 2023-08-04  发布在  Cassandra
关注(0)|答案(1)|浏览(119)

Cassandra的Stargate Document API提供了页面大小,以返回受页面大小限制的所有文档。页面大小的最大值为20。如何获取下一个文件;即21至30?
使用Cassandra的Stargate API阅读文档

rdlzhqv9

rdlzhqv91#

因此,当您对初始值20运行查询时,您将在返回的JSON中获得一个名为pageState的属性。下面是一个page-size=5的例子:

% curl --request GET \
  --url https://$ASTRA_DB_ID-$ASTRA_DB_REGION.apps.astra.datastax.com/api/rest/v2/namespaces/$ASTRA_DB_KEYSPACE/collections/hello_docs\?page-size\=5 \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H 'Content-Type: application/json'
{"pageState":"JGNlYjczMDc5LTE1NTItNGQyNS1hM2ExLWE2MzgxNWVlYTAyMADwf_____B_____","data":{
"58b12778-0efd-466e-89bf-66a4c99adee1":{"author":"Tom Clancy","title":"Red Rabbit"},
"77fe8690-f8d4-43b8-b1c9-a328318d4eae":{"author":"Tom Clancy","title":"Every Man a Tiger"},
"3177f86c-a633-4302-92a5-de4c15ab5840":{"author":"Tom Clancy","title":"Rainbow Six"},
"cefc7117-fc73-47b8-a965-099cf3a59269":{"author":"Tom Clancy","title":"Clear and Present Danger"},
"ceb73079-1552-4d25-a3a1-a63815eea020":{"author":"Tom Clancy","title":"The Cardinal of the Kremlin"}}}%

字符串
当我想获取接下来的5个文档时,我重新运行相同的查询,但添加了page-state参数,其中包含从前面的结果返回的值:

&page-state\=JGNlYjczMDc5LTE1NTItNGQyNS1hM2ExLWE2MzgxNWVlYTAyMADwf_____B_____


当我将它添加到原始查询时,它看起来像这样:

% curl --request GET \
--url https://$ASTRA_DB_ID-$ASTRA_DB_REGION.apps.astra.datastax.com/api/rest/v2/namespaces/$ASTRA_DB_KEYSPACE/collections/hello_docs\?page-size\=5\&page-state\=JGNlYjczMDc5LTE1NTItNGQyNS1hM2ExLWE2MzgxNWVlYTAyMADwf_____B_____ \
-H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
-H 'Content-Type: application/json'

 {"pageState":"JDUxMzVmMzFiLWY4NDYtNGZiNy1iNmFmLTk2YmU2OTMyNzlmMQDwf_____B_____","data":{
"f42cc7d8-81ba-41d5-b5c9-c13f8d0009c6":{"author":"Tom Clancy","title":"Patriot Games"},
"46df315f-7208-4859-af1c-96c4953f70c7":{"author":"Tom Clancy","title":"Without Remorse"},
"b23af545-4fdc-4ac5-907a-7132d7429d26":{"author":"Tom Clancy","title":"The Hunt for Red October"},
"c6d55ecd-1631-4d5c-8320-d111662f8837":{"other":"This is nonsensical stuff.","title":"Some Stuff"},
"5135f31b-f846-4fb7-b6af-96be693279f1":{"author":"Tom Clancy","title":"The Sum of all Fears"}}}%

tl;dr;

加上结果中返回的pageState,您应该得到下一个20。

编辑20211011

Stargate文档已更新,详细说明了此过程。
使用分页检索所有文档

相关问题