Created
December 7, 2015 20:37
-
-
Save shentonfreude/baa389de1770d68fe0bd to your computer and use it in GitHub Desktop.
AWS CloudSearch with pages using cursor (can only go forward, not back)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
# Returned 'cursor' can be of seemingly any length, and changes on each return | |
cs = boto3.client('cloudsearchdomain', | |
endpoint_url='https://search-thing-xxx.us-east-1.cloudsearch.amazonaws.com', | |
region_name='us-east-1') | |
size = 4 | |
cursor = 'initial' | |
while True: | |
ret = cs.search(query='nasa', cursor=cursor, size=size) | |
hit = ret['hits']['hit'] | |
if not hit: | |
break | |
print('{:32} {}'.format(cursor[-32:], ' | '.join([h['id'] for h in hit]))) | |
cursor = ret['hits']['cursor'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment