-
-
Save 4tikhonov/4048bbeb0ff1c397226b5a0d59f8e60c to your computer and use it in GitHub Desktop.
Minimal Working example of Elasticsearch scrolling using Python client
This file contains 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
# Initialize the scroll | |
page = es.search( | |
index = 'yourIndex', | |
doc_type = 'yourType', | |
scroll = '2m', | |
search_type = 'scan', | |
size = 1000, | |
body = { | |
# Your query's body | |
}) | |
sid = page['_scroll_id'] | |
scroll_size = page['hits']['total'] | |
# Start scrolling | |
while (scroll_size > 0): | |
print "Scrolling..." | |
page = es.scroll(scroll_id = sid, scroll = '2m') | |
# Update the scroll ID | |
sid = page['_scroll_id'] | |
# Get the number of results that we returned in the last scroll | |
scroll_size = len(page['hits']['hits']) | |
print "scroll size: " + str(scroll_size) | |
# Do something with the obtained page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment