Skip to content

Instantly share code, notes, and snippets.

@shentonfreude
Created December 7, 2015 20:37
Show Gist options
  • Save shentonfreude/baa389de1770d68fe0bd to your computer and use it in GitHub Desktop.
Save shentonfreude/baa389de1770d68fe0bd to your computer and use it in GitHub Desktop.
AWS CloudSearch with pages using cursor (can only go forward, not back)
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