Skip to content

Instantly share code, notes, and snippets.

@shentonfreude
Last active December 7, 2015 20:38
Show Gist options
  • Save shentonfreude/747300dbd0438a628264 to your computer and use it in GitHub Desktop.
Save shentonfreude/747300dbd0438a628264 to your computer and use it in GitHub Desktop.
AWS CloudSearch with pages: limit of 10,000 results but can go backward and forward
import boto3
# found is always the same
# start is the index into the total results, not a page of size results
cs = boto3.client('cloudsearchdomain',
endpoint_url='https://search-name-xxx.us-east-1.cloudsearch.amazonaws.com',
region_name='us-east-1')
size = 4
start = 0
while True:
ret = cs.search(query='nasa', start=start, size=4)
found = ret['hits']['found']
hit = ret['hits']['hit']
if not hit:
break
print('f={} p={} {}'.format(found, start, ' | '.join([h['id'] for h in hit])))
start += size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment